- Full-Stack Vue.js 2 and Laravel 5
- Anthony Gore
- 103字
- 2021-07-02 19:57:24
Methods
The Vue configuration object also has a section formethods. Methods are not reactive, so you could define them outside of the Vue configuration without any difference in functionality, but the advantage to Vue methods is that they are passed the Vue instance as context and therefore have easy access to your other properties and methods.
Let's refactor ourescapeKeyListenerto be a Vue instance method.
app.js:
var app = new Vue({ data: { ... }, methods: { escapeKeyListener: function(evt) { if (evt.keyCode === 27 && this.modalOpen) { this.modalOpen = false; } } }, watch: { ... },
created: function() { document.addEventListener('keyup', this.escapeKeyListener); } });
推薦閱讀
- Mastering OpenLayers 3
- 新編Visual Basic程序設計上機實驗教程
- JSP網絡編程(學習筆記)
- Learn TypeScript 3 by Building Web Applications
- Software Defined Networking with OpenFlow
- Go語言高效編程:原理、可觀測性與優化
- 樂學Web編程:網站制作不神秘
- Learning Elixir
- DevOps入門與實踐
- Instant QlikView 11 Application Development
- Learning Selenium Testing Tools(Third Edition)
- Python漫游數學王國:高等數學、線性代數、數理統計及運籌學
- C語言實驗指導及習題解析
- HTML5 APP開發從入門到精通(微課精編版)
- Python:Deeper Insights into Machine Learning