官术网_书友最值得收藏!

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); } });
主站蜘蛛池模板: 湖口县| 长乐市| 庆安县| 平舆县| 昌都县| 峡江县| 简阳市| 廊坊市| 广河县| 剑阁县| 方城县| 泰宁县| 双鸭山市| 涞水县| 通化市| 北川| 榆树市| 河北省| 海阳市| 通许县| 稻城县| 尤溪县| 斗六市| 南澳县| 松阳县| 司法| 措勤县| 定陶县| 琼中| 本溪市| 光山县| 浪卡子县| 丹东市| 清新县| 贺州市| 南乐县| 客服| 扶沟县| 祁连县| 昭觉县| 武夷山市|