Is it possible to nest methods in Vue.js in order to group related methods?

后端 未结 5 764
礼貌的吻别
礼貌的吻别 2021-02-06 06:33

I\'d like to group some of my Vue.js methods together in a sort of \"submethod\" class, but I only seem to be able to have single level methods.

For example, if I wanted

5条回答
  •  耶瑟儿~
    2021-02-06 07:15

    There is actually a very simple technique: create your nested methods in the created hook:

    created() {
      this.on = {
        test: () => {console.log(this)}
      }
      this.on.test();
    }
    

提交回复
热议问题