- 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); } });
推薦閱讀
- Learning RxJava
- 跟老齊學Python:輕松入門
- 青少年Python編程入門
- Learning Concurrent Programming in Scala
- Learning Concurrency in Kotlin
- Node Cookbook(Second Edition)
- 一本書講透Java線程:原理與實踐
- 基于SpringBoot實現(xiàn):Java分布式中間件開發(fā)入門與實戰(zhàn)
- BeagleBone Robotic Projects(Second Edition)
- 零代碼實戰(zhàn):企業(yè)級應用搭建與案例詳解
- 自學Python:編程基礎、科學計算及數(shù)據(jù)分析(第2版)
- 零基礎看圖學ScratchJr:少兒趣味編程(全彩大字版)
- 遠方:兩位持續(xù)創(chuàng)業(yè)者的點滴思考
- Moodle 3 Administration(Third Edition)
- Julia High Performance(Second Edition)