- 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!
- Rust實(shí)戰(zhàn)
- Power Up Your PowToon Studio Project
- 深入淺出Java虛擬機(jī):JVM原理與實(shí)戰(zhàn)
- 精通軟件性能測(cè)試與LoadRunner實(shí)戰(zhàn)(第2版)
- 教孩子學(xué)編程:C++入門(mén)圖解
- Python數(shù)據(jù)挖掘與機(jī)器學(xué)習(xí)實(shí)戰(zhàn)
- 零基礎(chǔ)學(xué)Python網(wǎng)絡(luò)爬蟲(chóng)案例實(shí)戰(zhàn)全流程詳解(高級(jí)進(jìn)階篇)
- Node.js Design Patterns
- PHP 7+MySQL 8動(dòng)態(tài)網(wǎng)站開(kāi)發(fā)從入門(mén)到精通(視頻教學(xué)版)
- Keras深度學(xué)習(xí)實(shí)戰(zhàn)
- Unity 2017 Mobile Game Development
- Getting Started with Nano Server
- Orleans:構(gòu)建高性能分布式Actor服務(wù)
- Delphi開(kāi)發(fā)典型模塊大全(修訂版)
- After Effects CC技術(shù)大全