Vue回调函数及继续操作组件方法

1.假如你不会使用ES6箭头函数,那么可使用funciton回调函数,但是在回调funciton中无法操作组件,怎么办呢,那么往下看

1.被调用的函数
showDOMVisible()
{
        //2.调用查询函数,将this传入函数
        this.queryAction(1, this, function(self, data) {
              //5.执行回调后动作,对传入的this做使用
              console.log("showVisible-->显示", self, data);
              //需要显示的Dialog
              self.domVisible = true;
              //需要显示文字的双向绑定组件
              self.InfoHTML = data;
        })
},
queryAction(actionCode, self, callBack)
{
    //3.发送后台请求
    console.log("showCopyVisible");
    let urlPath= "/actionName/getLog?a=1" ;
    this.$axios.post(urlPath, {})
        .then((response) => {
                      //返回成功
            if("0" == response.data.code)
            {
                console.log("queryAction-->回调");
                                //4.得到后台请求结果,回调函数
                callBack(self, response.data.data)
            }
        })
},

你可能感兴趣的:(Vue回调函数及继续操作组件方法)