- 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); } });
推薦閱讀
- ExtGWT Rich Internet Application Cookbook
- Mastering Natural Language Processing with Python
- JavaScript+jQuery開發實戰
- NativeScript for Angular Mobile Development
- Instant QlikView 11 Application Development
- 青少年學Python(第1冊)
- SQL Server與JSP動態網站開發
- 從零開始學Linux編程
- OpenGL Data Visualization Cookbook
- 基于SpringBoot實現:Java分布式中間件開發入門與實戰
- Azure Serverless Computing Cookbook
- Android應用開發實戰
- 從零開始學Android開發
- ABAQUS6.14中文版有限元分析與實例詳解
- Python硬件編程實戰