美文网首页
2018-01-13

2018-01-13

作者: 长歌_4e85 | 来源:发表于2018-01-13 12:27 被阅读0次

Vue  用模块化的方式构建项目


想要提高代码的复用性,vue 项目中可以使用插件的方法:

<code>

MyPlugin.install = function (Vue, options) {

// 1. 添加全局方法或属性

    Vue.myGlobalMethod =function(){

        // 逻辑...

      }

// 2. 添加全局资源

Vue.directive('my-directive', {

    bind (el, binding, vnode, oldVnode) {

        // 逻辑...

    }

    ...

  })

// 3. 注入组件

  Vue.mixin({

    created:function(){

        // 逻辑...

    }

    ...

  })

// 4. 添加实例方法

Vue.prototype.$myMethod =function(methodOptions){

    // 逻辑...

  }

}

</code>

相关文章

网友评论

      本文标题:2018-01-13

      本文链接:https://www.haomeiwen.com/subject/errcoxtx.html