Skip to content

Commit

Permalink
Define 'queryParam' in data
Browse files Browse the repository at this point in the history
  • Loading branch information
smori1983 committed Oct 1, 2023
1 parent f7195c6 commit 8e8c9a6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/components/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export default {
query: '',
searchResult: [],
queryParam: 'q',
};
},
Expand All @@ -59,26 +61,26 @@ export default {
this.database.add(locale, data[locale] || {});
}
this.query = this.$router.currentRoute.query.q || '';
this.query = this.$router.currentRoute.query[this.queryParam] || '';
this.updateSearchResult();
},
watch: {
$route (to, from) {
this.query = to.query.q || '';
this.query = to.query[this.queryParam] || '';
this.updateSearchResult();
},
},
methods: {
submit () {
const queryParam = this.$router.currentRoute.query.q || '';
const queryParam = this.$router.currentRoute.query[this.queryParam] || '';
const query = this.query;
if (queryParam !== query) {
this.$router.push({
path: this.$router.currentRoute.path,
query: {
q: query,
[this.queryParam]: query,
},
});
}
Expand Down

0 comments on commit 8e8c9a6

Please sign in to comment.