- 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!
- Three.js開發指南:基于WebGL和HTML5在網頁上渲染3D圖形和動畫(原書第3版)
- 羅克韋爾ControlLogix系統應用技術
- Mastering Data Mining with Python:Find patterns hidden in your data
- OpenCV 4計算機視覺項目實戰(原書第2版)
- Vue.js 2 Web Development Projects
- 零基礎學C語言第2版
- C語言程序設計簡明教程:Qt實戰
- Visual Basic程序設計(第三版)
- JavaScript程序設計:基礎·PHP·XML
- Deep Learning with R Cookbook
- 遠方:兩位持續創業者的點滴思考
- Python第三方庫開發應用實戰
- Manage Your SAP Projects with SAP Activate
- Unreal Engine Game Development Cookbook
- 算法學習與應用從入門到精通