嗨,我正在测试我的 vuex 动作异步函数,它通过 axios 调用 api,但我有一些问题,它显示这样的错误“类型错误:无法解构data‘未定义’或‘空’的属性。
35 | commit('storeSearchValue', name);
36 | const url = process.env.VUE_APP_URL_API_News + '/news' + '?q=' + name;
> 37 | const { data } = await axios.get(url);"
Run Code Online (Sandbox Code Playgroud)
我的 vue js 代码是
async updateSearchValue({ commit }, name) {
commit('storeSearchValue', name);
const url = process.env.VUE_APP_URL_API_News + '/news' + '?q=' + name;
const { data } = await axios.get(url);
commit('storeNewsData', data.result);
},
Run Code Online (Sandbox Code Playgroud)
这是测试文件,
import actions from '@/store/modules/data/data-actions.js'
import VueRouter from 'vue-router';
import axios from 'axios';
import …Run Code Online (Sandbox Code Playgroud)