Как получить get параметры из URL в Nuxt.js
Пишу проект на Nuxt есть необходимость получать гет параметры из URL хочу написать что то типо этого
fetch ({store}) {
let requestPageApi = axios.get('http://localhost:3005/search/?' + this.$route.query).then((res) => { .....
.
Мой код Nuxt.js
import axios from "axios";
export default {
name: "index",
fetch ({store}) {
let requestPageApi = axios.get('http://localhost:3005/search/', { params: { q: this.$route.query.search } }).then((res) => {
store.commit('frontPagePosts', res.data.tours.posts)
store.commit('routePageHead', res.data.head)
// console.log(res.data)
}).catch((error) => {
console.log(error)
})
return requestPageApi
},
Ответы (1 шт):
Автор решения: eri
→ Ссылка
Gет параметры в атрибуте this.$route.query
axios.get('http://localhost:3005/search/', { params: { q: this.$route.query.search } }
в методе fetch доступен this, так что инъекция тут не особо нужна.
Проверил в своём проекте - роут есть.
Возможно из-за инжекта ({store}) ... попробуй ({store, route}) и забрать route.query. Возможно из-за ssr - я его не использую.
