vue 插件

export default {
    install(vue, options) {
        console.log(vue);
        console.log(options);
        // vue.add()
        vue.add = function foo(a, b) {
            console.log('add result is :', a + b);
        };
        // this.reduce()
        vue.prototype.reduce = function bar(a, b) {
            console.log('reduce:', a - b);
        };
        vue.directive('form', {
            acceptStatement: true,
            bind(el, binding, vnode, oldVnode) {
                // 获取绑定的元素,节点。。。
                console.log('bind', el, binding, vnode, oldVnode);
            },
            unbind() {
                console.log('unbind');
            },
            update(fn) {
                console.log('fn is ', fn);
            },
        });
        // mixin 混合created()
        vue.mixin({
            created() {
                console.log('组件开始加载');
            }
        });
    },
};
    原文作者:酷吧你我他
    原文地址: https://segmentfault.com/a/1190000010126546
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞