我已安装@nuxtjs/toast
并在我的应用程序中正常工作。
我想在分派行动后举杯祝酒。
我如何在vuex存储区的模块中的操作中访问$toast
?
PS:我正在将Nuxt与打字稿一起使用,并且从intellisense看来,我只能访问$ router和$ axios。
export const actions: ActionTree<ProfileState, RootState> = {
async updateProfile({ }, user) {
console.log(user);
const newUserObj = await this.$axios.post("/me/update", user).then(res => res.data.data);
console.log(newUserObj);
// this.$toast.info("Hello");
// commit('LOAD_NEW_USER', newUserObj);
},
}
答案 0 :(得分:2)
首先,让我们解决您的问题
async updateProfile({commit}, user) {
return new Promise(async(resolve,reject)=>{
try {
const newUserObj = await this.$axios.$post("/me/update", user)
commit('SET_USER',newUserObj)
resolve(newUserObj)
} catch (error) {
reject(error)
}
})
},
展示面包-
尝试在this.app.$toast
行下方的commit('SET_USER',newUserObj)