【发布时间】:2020-08-24 12:49:41
【问题描述】:
所以我试图让我的 Axios 使用一个参数来执行获取请求,该参数将在中结束 url
'/?user= {id}'
id 是由我的 Vuex 中的 loggedInUser.id 传入的。我知道异步函数在调用中不会接受“this”,所以我将 store 作为参数包含在内。我认为我如何传递数据的方式仍然存在问题。非常感谢任何帮助,谢谢!
import { mapGetters } from "vuex";
export default {
computed: {
...mapGetters(["loggedInUser"])
},
head() {
return {
title: "Actors list"
};
},
components: {
EditProfile
},
async asyncData({ store }) {
try {
const body = { data: store.getters.loggedInUser.id };
const { actors } = await $axios.$get(`/api/v1/actors/`, {
params: {
user: body
}
});
return { actors };
} catch (e) {
return { actors: [] };
}
},
data() {
return {
actors: []
};
编辑
当我从 'const body' 中删除数据并删除了 'actor' 周围的括号时,我得到了它的工作
try {
const body = store.getters.loggedInUser.id;
const actors = await $axios.$get(`/api/v1/actors/`, {
params: {
user: body
}
});
【问题讨论】:
标签: vue.js vuejs2 vuex nuxt.js