我是分发两个fetch函数去不同地方拿数据
然后我现在想要将两个结果数据做一些合并 然后放到一个table里去
也就是两个action的函数做完一起mutation,这样可行吗
请问该怎么写呀
const actions = {
getLatestJob(context){
const result=api.getJobJson(context);
result.then(function (res) {
console.log("----------------------JSON QUERY NBU JOB: res.status:"+res.status);
if(res.status === 200){
return res.json()
}
}).then(function (json) {
console.log(typeof Array.from(json), Array.from(json));
context.commit('setJson', json);
})
},
getLatestJobFromShield(context){
const result=api.getJobJsonFromShield(context);
result.then(function (res) {
console.log("----------------------JSON QUERY Shield JOB: res.status:"+res.status);
if(res.status === 200){
return res.json()
}
}).then(function (json) {
console.log(typeof Array.from(json), Array.from(json));
//context.commit('setJson', json);
})
}
};
//mutation 官方推荐的修改状态的方式
const mutations = {
setJson(state,db){
然后vue里面
getJson(){
this.$store.dispatch("getLatestJob");
this.$store.dispatch("getLatestJobFromShield");
},
问题出现的环境背景及自己尝试过哪些方法
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
两个方法算出的结果传入一个vuex中的函数,在函数中根据两个传参算出结果即可