getUser () {
return new Promise((resolve) => {
getUser({ areaCode: this.activeName }).then((res) => {
this.credentNo = res.data.credentNo
resolve(true)
})
})
},
getGrowthValue () {
return new Promise((resolve) => {
getGrowthValue({ areaCode: this.activeName }).then((res) => {
if (res.data) {
this.growthInfo = res.data
resolve(true)
}
})
})
}
等待上面两个接口请求完再执行下一步(如何不等接口执行完跳转到其他地方将会出现接口拿不到返回值的情况)
return Promise.all([this.getMyRanking(), this.getGrowthValue()]).then(function (results) {
console.log(results); // 获得一个Array: ['P1', 'P2']
_this.goPower(item)
});
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
在vuex里面存储的数据,刷新页面就会不见,使用sessionStorage保存数据刷新接口也不会丢失
//向seaaionStorage里面存数据
sessionStorage.setItem("activeName", this.activeName);
//从seaaionStorage里面取数据
window.sessionStorage.getItem('activeName')
//清除sessionStorage里面的数据
window.sessionStorage.removeItem('activeName')
存储对象
sessionStorage.setItem("primaryTowStep", JSON.stringify(values));
// 获取session参数对象
getSessionObj: (name) => {
const strObj = window.sessionStorage.getItem(name)
/
try {
const data = JSON.parse(strObj)
return data
} catch (error) {
return null
}
},
/
想要接口只调一遍在stroe的account里面写
findArea ({ state, commit }) {
return new Promise((resolve) => {
//如果有值不再调用
if (state.areaList && state.areaList.length > 0) {
resolve(state.areaList)
return
}
findArea({ type: 'AREA_CODE' }).then(res => {
commit('SET_AREALIST', res.data)
resolve(res.data)
}).catch(() => {
commit('SET_AREALIST', [])
})
})
}
/ 需要调用的地方使用 this.$store.dispatch res为抛出的值
this.$store.dispatch('findArea').then((res) => {
this.areaList = res
this.getFindArea()
})