如何在Nuxt vuex商店中访问$toast



我已经安装了@nuxtjs/toast,并且在我的应用程序中正常工作。

我想在行动发出后举杯庆祝。我如何在vuex商店中的模块中的操作中访问$toast

附言:我正在使用带有typescript的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);
},
}

首先,让我们修复您的操作

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)
}

})
},

显示吐司-

尝试commit('SET_USER',newUserObj)线下方的this.app.$toast

最新更新