Pay attention to the pointing of this in Vue's this.$confirm

During the development process of Vue, we encountered the failure problem of this in this. confirm (), that is, when you want to use data data in it, we often get the value in this . data Name method, but in this . confirm() ), the this failure problem is that when you want to use data data in it, we often get the value through this.dataName, but in this.The problem of thi s failure in con fi r m ( ) is that when you want to use data data in it , we often get it in this way thi s . d a t a N am e value, but this in thi s . confirm() does not point to the current vue, so the data cannot be obtained.

Solution:
So we save this before using this.$confirm()

let _this = this
			const _this = this
            this.$confirm({
    
    
              title: '當前郵件正文内容爲空',
              content: h => <div style="color:red;">確認是否發佈?</div>,
              onOk () {
    
    
                console.log('保存提交的对象', this.objData)
                _this.loading = true
                initAxios.saveMail(_this.objData).then((res) => {
    
    
                  _this.loading = false
                  if (res.data.code === '200' && res.data.result) {
    
    
                    _this.$router.go(-1) // 处理返回需要点两次的问题
                    _this.$message.success('發佈成功!')
                  }
                })
              },
              onCancel () {
    
    
                return false
              }
            })

Guess you like

Origin blog.csdn.net/weixin_44786330/article/details/128897168