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

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); } });
主站蜘蛛池模板: 河北区| 襄樊市| 南岸区| 永春县| 运城市| 安乡县| 合作市| 南京市| 全椒县| 江北区| 武胜县| 得荣县| 于田县| 苗栗市| 大安市| 三门县| 西峡县| 雷州市| 调兵山市| 罗山县| 法库县| 游戏| 澜沧| 子长县| 湖南省| 凤城市| 和政县| 聊城市| 黄冈市| 高密市| 二连浩特市| 龙州县| 濉溪县| 阜阳市| 竹北市| 怀宁县| 佛冈县| 门源| 临颍县| 革吉县| 肃宁县|