当前位置: 移动技术网 > IT编程>开发语言>JavaScript > vue中computed计算属性与methods对象中的this指针

vue中computed计算属性与methods对象中的this指针

2019年03月10日  | 移动技术网IT编程  | 我要评论

this 指针问题

methods与computed中的this指针 应该指向的是它们自己,可是为什么this指针却可以访问data对象中的成员呢?

因为new vue对象实例化后data中的成员和computed中的成员为实现化对象属性了,而methods中定义的方法为实现化对象方法了。这时this指针指向的是这个实现化对象。

    let v = new vue({
        el: '.test',
        data: {
            title: "121213"
        },
        methods: {
            msg() {
                alert(this.title); // ?? this 指针
            }
        },
        computed: { 
            prefixtitle() {
                return "¥" + this.title;// ?? this 指针
            }
        }
    });

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网