- Full-Stack Vue.js 2 and Laravel 5
- Anthony Gore
- 157字
- 2021-07-02 19:57:24
Proxied properties
You may have noticed that ourescapeKeyListenermethod can refer tothis.modalOpen. Shouldn't it bethis.methods.modalOpen?
When a Vue instance is constructed, it proxies any data properties, methods, and computed properties to the instance object. This means that from within any method you can refer tothis.myDataProperty,this.myMethod, and so on, rather thanthis.data.myDataPropertyorthis.methods.myMethod,as you might assume:
var app = new Vue({ data: { myDataProperty: 'Hello' }, methods: { myMethod: function() { return this.myDataProperty + ' World'; } } }); console.log(app.myMethod()); // Output: 'Hello World'
You can see these proxied properties by printing the Vue object in the browser console:

Figure 2.12. Our app's Vue instance
Now the simplicity of text interpolations might make more sense, they have the context of the Vue instance, and thanks to proxied properties, can be referenced like{{ myDataProperty }}.
However, while proxying to the root makes syntax terser, a consequence is that you can't name your data properties, methods, or computed properties with the same name!
- 深度實踐OpenStack:基于Python的OpenStack組件開發
- Python 3.7網絡爬蟲快速入門
- 工程軟件開發技術基礎
- 自制編譯器
- 騰訊iOS測試實踐
- Mastering Selenium WebDriver
- Access 數據庫應用教程
- 新手學Visual C# 2008程序設計
- Rust Essentials(Second Edition)
- Learning Python Design Patterns
- MATLAB 2020從入門到精通
- Mastering React
- 區塊鏈架構之美:從比特幣、以太坊、超級賬本看區塊鏈架構設計
- Fastdata Processing with Spark
- 算法設計與分析:基于C++編程語言的描述