25.06.2018 Views

Full-Stack Vue.js 2 and Laravel 5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Proxied properties<br />

You may have noticed that our escapeKeyListener method can refer to this.modalOpen.<br />

Shouldn't it be this.methods.modalOpen?<br />

When a <strong>Vue</strong> instance is constructed, it proxies any data properties, methods, <strong>and</strong><br />

computed properties to the instance object. This means that from within any<br />

method you can refer to this.myDataProperty, this.myMethod, <strong>and</strong> so on, rather than<br />

this.data.myDataProperty or this.methods.myMethod, as you might assume: var app =<br />

new <strong>Vue</strong>({ data: { myDataProperty: 'Hello' }, methods: { myMethod: function()<br />

{ return this.myDataProperty + ' World'; } } }); console.log(app.myMethod()); //<br />

Output: 'Hello World'<br />

You can see these proxied properties by printing the <strong>Vue</strong> object in the browser<br />

console:<br />

Figure 2.12. Our app's <strong>Vue</strong> instance Now the simplicity of text interpolations might make more sense, they<br />

have the context of the <strong>Vue</strong> instance, <strong>and</strong> thanks to proxied properties, can be referenced like {{<br />

myDataProperty }}.<br />

However, while proxying to the root makes syntax terser, a consequence is that<br />

you can't name your data properties, methods, or computed properties with the<br />

same name!

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!