vuex中的 actions 中,是不能使用 this.$message.error() 的

vuex 中如何获取 vue 的 this ?

vuex 中的 actions 中,是不能使用 this.$message.error('xxx失败') 的,

因为,vuex中没有.vue中的this,但是,可以通过下面这种方法哦,如下:

某.vue文件
javascript 复制代码
this.$store.dispatch('xxx', {
	form: data.form,
    _this: this // 在这里传入该组件的this,vuex中即可获取this
})
vuex中
javascript 复制代码
async xxx({ commit, state }, payload) {
      let { _this } = payload
      try {
        let { state, data, message } = await fafaApi.getVerifyFilmList()
        if (state === 200) {
          commit('SET_TASK_DATA', filteredData)
        } else {
          _this.$message.error(message)
        }
      } catch (error) {
        _this.$message.error(error)
      }
}
相关推荐
老男孩游戏时光7 小时前
Vue3 Composition API 最佳实践,别再乱写 setup 了
vue.js
+VX:Fegn08957 小时前
计算机毕业设计|基于java+ vue共享单车信息系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
Bs_MoneyMagnet7 小时前
基于springboot+vue的非遗物质文化遗产系统的设计与实现 源码+文档
java·vue.js·spring boot·后端·spring·毕业设计·计算机毕业设计
计算机毕设定制辅导-无忧学长8 小时前
《基于SpringBoot的未成年人健康知识科普平台的设计与实现》
java·开发语言·vue.js·spring boot·未成年人健康知识科普平台
专业程序开发源10 小时前
springboot篮球联赛管理系统13635-计算机课程设计、毕业设计
vue.js·spring boot·后端·python·django·php·课程设计
一 乐11 小时前
自习室座位预约管理系统|基于springboot + vue自习室座位预约管理系统(源码+数据库+文档)
java·vue.js·spring boot
晚安日记wanna11 小时前
Vue2 的 defineProperty 差在哪四层追问筛掉九成候选人
前端·vue.js·面试
dy17171 天前
vue2树节点刷新后定位到上一节点展开
vue.js
高级程序源1 天前
django大学生创新创业项目管理系统94923-计算机课程设计、毕业设计
javascript·vue.js·spring boot·后端·python·django·课程设计
VXbishe1 天前
【课程设计】基于SpringBoot的乡村政务服务系统的设计与实现-计算机毕设77011
javascript·vue.js·spring boot·python·php·课程设计·政务