路由器推送后在 asyncData 中获取路由参数
get route params in asyncData after router push
我试图在 asyncData 方法中获取路由参数,如果我手动转到路由,它会工作,但如果我使用路由器 Push 方法,它不会获取任何参数。
这是我的 asynData 方法:
async asyncData(ctx) {
const { id } = ctx.app.router.currentRoute.params
await ctx.store.dispatch('user/GET_USER', id)
return {
user: ctx.store.state.user.user
}
},
这就是我导航到相应页面的方式:
goToEdit(id) {
this.$router.push({ path: `/users/${id}/edit` })
}
你需要直接从ctx获取路由。 Here 上下文参数列表
async asyncData({ route }) {
const { id } = route.params
await ctx.store.dispatch('user/GET_USER', id)
return {
user: ctx.store.state.user.user
}
},
我正在以类似的方式进行操作,但我从 context
.
中检索参数和几乎所有内容
async asyncData(context) {
const plans = await context.$axios.get("business/get-plans", {
params: {
currency: context.query.currency
}
}).then((res) => {
return res.data;
});
看看 context.$axios
和 context.query
。
我试图在 asyncData 方法中获取路由参数,如果我手动转到路由,它会工作,但如果我使用路由器 Push 方法,它不会获取任何参数。
这是我的 asynData 方法:
async asyncData(ctx) {
const { id } = ctx.app.router.currentRoute.params
await ctx.store.dispatch('user/GET_USER', id)
return {
user: ctx.store.state.user.user
}
},
这就是我导航到相应页面的方式:
goToEdit(id) {
this.$router.push({ path: `/users/${id}/edit` })
}
你需要直接从ctx获取路由。 Here 上下文参数列表
async asyncData({ route }) {
const { id } = route.params
await ctx.store.dispatch('user/GET_USER', id)
return {
user: ctx.store.state.user.user
}
},
我正在以类似的方式进行操作,但我从 context
.
async asyncData(context) {
const plans = await context.$axios.get("business/get-plans", {
params: {
currency: context.query.currency
}
}).then((res) => {
return res.data;
});
看看 context.$axios
和 context.query
。