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

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); } });
主站蜘蛛池模板: 巫溪县| 广德县| 怀柔区| 灵璧县| 桃江县| 平塘县| 铁岭县| 咸宁市| 乳源| 武宁县| 平阳县| 罗源县| 弋阳县| 葫芦岛市| 岳阳县| 信宜市| 大宁县| 铁力市| 民勤县| 甘肃省| 上饶县| 凤阳县| 海原县| 阿勒泰市| 新野县| 石林| 大英县| 宁安市| 义乌市| 会东县| 建宁县| 昆明市| 鄂尔多斯市| 吴旗县| 泰兴市| 息烽县| 淳化县| 临清市| 荥经县| 伊吾县| 金秀|