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

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); } });
主站蜘蛛池模板: 酒泉市| 衡阳县| 淄博市| 五大连池市| 玉龙| 汤原县| 惠州市| 丹巴县| 湄潭县| 温宿县| 大埔县| 丽水市| 天长市| 永春县| 福安市| 天峻县| 临江市| 平乡县| 通榆县| 磴口县| 黎平县| 五常市| 白银市| 名山县| 青田县| 博罗县| 麦盖提县| 文安县| 博兴县| 依兰县| 台州市| 姜堰市| 长兴县| 罗山县| 武安市| 曲周县| 洛浦县| 贞丰县| 天门市| 乐陵市| 淅川县|