diff --git a/src/App.vue b/src/App.vue index 2e7c1f058a3f59e0dda68f6c8c6502cd514ca4c3..6dfc470b5897fd24180629342337e329e11bac69 100644 --- a/src/App.vue +++ b/src/App.vue @@ -68,8 +68,11 @@ axios.interceptors.request.use(function (config) { window.onpopstate = function (event) { if (event.state) { + // eslint-disable-next-line app.__vue__._data.article = event.state.article + // eslint-disable-next-line app.__vue__._data.search_results = event.state.search_results + // eslint-disable-next-line app.__vue__._data.lang = event.state.lang } } @@ -86,11 +89,14 @@ export default { } }, computed: { + api_pref: function() { + return api_endpoint + '/' + this.lang + '/article/' + }, search: function() { let self = this return function(q) { return new Promise(resolve => { - return axios.get(api_endpoint + '/' + self.lang + '/article/suggest?q=' + q).then( + return axios.get(self.api_pref + 'suggest?q=' + q).then( function(response) { let hits = q.length ? [{q: q}] : [] hits = hits.concat(response.data.suggest.suggest[0].options.sort((o1, o2) => o1.text.length - o2.text.length)) @@ -119,7 +125,7 @@ export default { var self = this self.waiting = true self.article = {lemmas: [], body:{pronunciation: [], definitions: [], etymology: []}} - axios.get(api_endpoint + '/' + self.lang + '/article/search?q=' + event.q + ' ' + event.q + '*&size=20') + axios.get(self.api_pref + 'search?q=' + event.q + ' ' + event.q + '*&size=20') .then(function(response){ self.$router.push('/' + `/search?q=${event.q}&lang=${self.lang}`) self.search_results = response.data.hits.hits @@ -136,7 +142,7 @@ export default { }else{ self.article = {lemmas: [], body:{pronunciation: [], definitions: [], etymology: []}} self.waiting = true - axios.get(api_endpoint + '/' + self.lang + '/article/' + item.article_id) + axios.get(self.api_pref + '' + item.article_id) .then(function(response){ self.article = response.data._source self.waiting = false @@ -154,7 +160,7 @@ export default { this.lang = this.$route.params.lang || this.$route.query.lang || 'bob,nob' var self = this; if(this.$route.query.q) { - axios.get(api_endpoint + '/' + self.lang + '/article/search?q=' + self.$route.query.q + ' ' + self.$route.query.q + '*&size=20') + axios.get(self.api_pref + 'search?q=' + self.$route.query.q + ' ' + self.$route.query.q + '*&size=20') .then(function(response){ self.search_results = response.data.hits.hits self.waiting = false @@ -162,7 +168,7 @@ export default { }) } else if(this.$route.params.id){ - axios.get(api_endpoint + '/' + self.lang + '/article/' + self.$route.params.id) + axios.get(self.api_pref + '' + self.$route.params.id) .then(function(response){ self.article = response.data._source self.waiting = false @@ -175,7 +181,7 @@ export default { } }, watch: { - $route(to, from) { + $route() { this.lang = this.$route.params.lang || this.$route.query.lang || 'bob,nob' } }