首页 > 其他 > 详细

vue mixin使用

时间:2018-09-19 21:05:30      阅读:210      评论:0      收藏:0      [点我收藏+]

1、概述

将一些公用方法引入到不同的组件中。

2、引入方式

(1)全局引入

// 注册全局Mixin
    Vue.mixin({
      methods: {
        $touch: function() { // 用以同时watch多个字段变化
          return Date.now();
        },
        anotherMethods: function() {
          console.log(8888)
        }
      }
    })

(2)局部引入

let myMixin = {
  methods: {
    hello: function() {
      console.log(‘hello from mixin!‘)
    }
  }
}

mixins: [myMixin],
mounted() {
      console.log(this.hello(), ‘$hello‘);
    },

混入对象可以包含任意组件选项

vue mixin使用

原文:https://www.cnblogs.com/mengfangui/p/9676532.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!