【发布时间】:2021-01-20 20:16:04
【问题描述】:
作为参数,我有一个“测试”id,我将它传递给存储,即 index.js。在控制台中,我有这个错误 -> users?id=[object%20Object]。我已经尝试过->“this.id.toString()”,但它不起作用。有人可以帮帮我吗?
用户.vue
<script>
import { mapActions } from "vuex";
export default {
data: () => ({
id: "test",
}),
methods: {
...mapActions("Test", [
"GET_USER_BY_ID",
]),
add() {
this.GET_USER_BY_ID(this.id);
},
},
};
</script>
index.js
import axios from '../../plugins/axios'
const actions = {
GET_USER_BY_ID(userId) {
console.log(userId)
return axios.get(`users?id=${userId}`)
.then((response) => {
console.log(response)
return response
})
}
export default {
namespaced: true,
state,
getters,
actions,
mutations
}
【问题讨论】:
-
[object Object] 是当您尝试将对象视为字符串时得到的(因此添加 .toString() 与您应该做的相反)。
标签: javascript vue.js axios vuetify.js