Skip to content

Commit

Permalink
Split methods
Browse files Browse the repository at this point in the history
  • Loading branch information
smori1983 committed Oct 1, 2023
1 parent a519c86 commit f7195c6
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/components/Form.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div>
<form
@submit.prevent="search"
@submit.prevent="submit"
class="search-form"
>
<input
Expand Down Expand Up @@ -60,41 +60,46 @@ export default {
}
this.query = this.$router.currentRoute.query.q || '';
this.search();
this.updateSearchResult();
},
watch: {
$route (to, from) {
this.query = to.query.q || '';
this.search();
this.updateSearchResult();
},
},
methods: {
search () {
const query = this.query.trim();
if (query.length === 0) {
this.searchResult = [];
}
const currentParam = this.$router.currentRoute.query.q || '';
if (currentParam !== query) {
submit () {
const queryParam = this.$router.currentRoute.query.q || '';
const query = this.query;
if (queryParam !== query) {
this.$router.push({
path: this.$router.currentRoute.path,
query: {
q: query,
},
});
}
},
updateSearchResult () {
this.searchResult = this.search();
},
search () {
const query = this.query.trim();
if (query.length === 0) {
return [];
}
const localePath = this.$localePath;
const queryForSearch = ngram.createForSearch(query, FLEX_SEARCH_NGRAM_SIZE);
const max = this.$site.themeConfig.searchMaxSuggestions || FLEX_SEARCH_MAX_SUGGESTIONS;
const matchedKeys = this.database.search(localePath, queryForSearch, max);
this.searchResult = matchedKeys.map((key) => {
return matchedKeys.map((key) => {
const page = data[localePath][key];
return {
Expand Down

0 comments on commit f7195c6

Please sign in to comment.