vue中computed計算屬性與methods對象中的this指針


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 指針
            }
        }
    });

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM