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'); },
混入对象可以包含任意组件选项。