zoukankan      html  css  js  c++  java
  • vue中this在回调函数中的使用

    this在各类回调中使用:

    如果是普通函数是没法使用的

    所以需要先将this.变量赋值给新的变量,然后才能在回调函数中使用
    
    例如:
    refund: function (id) {
          if (!this.url.refund) {
            this.$message.error("请设置url.refund属性!")
            return
          }
          var that = this;
          this.$confirm({
            title: "确认退款",
            content: "是否要进行退款?",
            onOk: function () {
              putAction(that.url.refund, { "id": id }).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                } else {
                  that.$message.warning(res.message);
                }
              });
            }
          });
        },
    

    如果是箭头函数式可以使用的

    下面的这个例子只是参考,并不代表this.$confirm就是这么使用,具体参考ant的文档
    下面的例子只是代表,箭头函数可以使用this
    efund: function (id) {
          if (!this.url.refund) {
            this.$message.error("请设置url.refund属性!")
            return
          }
          this.$confirm({
            title: "确认退款",
            content: "是否要进行退款?",
            onOk: () => {
              putAction(that.url.refund, { "id": id }).then((res) => {
                if (res.success) {
                  this.$message.success(res.message);
                  this.loadData();
                } else {
                  this.$message.warning(res.message);
                }
              });
            }
          });
        },
    
  • 相关阅读:
    Linux下安装漏洞扫描工具Nessus
    【译】使用OpenVAS 9进行漏洞扫描
    MD5小彩虹表
    获取某个版本软件存在的漏洞信息
    【译】使用chage来管理Linux密码过期时间的七个例子
    [转]Centos 安装Sublime text 3
    Nessus扫描策略
    Nginx使用笔记
    SSH 公钥登录
    MySQL加密
  • 原文地址:https://www.cnblogs.com/eternityz/p/12272467.html
Copyright © 2011-2022 走看看