在vuex中使用sweet alert toast进行错误处理



我已经在我的项目上安装了sweet alert。现在我想在Vuex actions中使用它,但它不起作用。

update({ commit, dispatch }, data) {
return new Promise(async (resolve, reject) => {
try {
const res = await update(data);
resolve(res.data)
this.app.$toast('this is a test toas', {
title: 'Test'
})
} catch (err) {
this.app.$toast('this is a test toas', {
title: 'Test'
})
reject(err.response);
}
})
},

它在组件中工作得很好,但我无法使用this.app.$toast访问它

$toast仅在component范围内可用,而不是vuex,我以前遇到过这样的问题,我将其作为toast的参考参数传递。

update({ commit, dispatch }, {data , that}) {
return new Promise(async (resolve, reject) => {
try {
const res = await update(data);
resolve(res.data)
that.$toast('this is a test toas', {
title: 'Test'
})
} catch (err) {
that.$toast('this is a test toas', {
title: 'Test'
})
reject(err.response);
}
})
当从组件调用update方法时,将此引用作为 传递。
update({
data,
that: this
})

最新更新