VUE data内 THIS 各种情况

var vm = new Vue({
        /* 在方法中,this 表示该方法所属的对象。
        如果单独使用,this 表示全局对象。
        在函数中,this 表示全局对象。
        在函数中,在严格模式下,this 是未定义的(undefined)。
        在事件中,this 表示接收事件的元素。
        类似 call() 和 apply() 方法可以将 this 引用到任何对象。
        */
        data: { 
            b: () => {
                console.log(this); 
                //window 箭头函数体中的 this 对象,是定义函数时的对象,而不是使用函数时的对象。没有 this、super、arguments 和 new.target 绑定。
                return function(){
                   return "";
                }
            },
            c: function(){
                console.log(this) //vue 在方法中,this 表示该方法所属的对象。
                return function(){
                    console.log(this) //window  回调方法写再一个回调方法内,回调方法本身不属于对象,所以this为全局得window
                    return "";     
                }
            },
            d : { a : this}, //window  如果单独使用,this 表示全局对象。
            e : {a :{ a: function(){
                console.log(this)  //observer 在方法中,this 表示该方法所属的对象。
                return '';
            }}},
            f : {a : function(){
                console.log(this) //observer 在方法中,this 表示该方法所属的对象。
                return '';
            }},
        }
    })

 

转载于:https://www.cnblogs.com/bin-pureLife/p/10416012.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值