在store
使用Promise 要用 then() 接收或者 async await 来修饰
避免出现提示
Promise {<pending>} 这个语句
index.js
import Vue from 'vue'
import Vuex from 'vuex'
import {GetCode} from "@/api/index";
Vue.use(Vuex)
export default new Vuex.Store({
state: {
listIndex: []//请求接口数据
},
mutations: {
saveValue(state, data) {
state.listIndex = data;
}
},
actions: {
//请求接口
rendNAv({commit,state }) {
return new Promise((resolve, reject) => {
let params = {
page: 1,
limit: 10,
}
GetCode({ params }).then((response) => {
resolve(response);
commit('saveValue', response.data)
})
.catch((response) => {
reject(response);
});
})
}
},
modules: {
}
})
其他页面调取
this.$store.dispatch('rendNAv').then(res=>{
console.log(res,'23232')
})