zoukankan      html  css  js  c++  java
  • vue install 注册组件

    1、myPlugin.js文件

    let MyPlugin = {};
    MyPlugin.install = function (Vue, options) {
      // 1. 添加全局方法或属性
      Vue.myGlobalMethod = function () {
        // 逻辑...
        console.log('myGlobalMethod')
      }
    
      // 2. 添加全局资源
      Vue.directive('my-directive', {
        bind (el, binding, vnode, oldVnode) {
          // 逻辑...
        }
      })
    
      // 3. 注入组件
      Vue.mixin({
        created: function () {
          // 逻辑...
        }
      })
    
      // 4. 添加实例方法
      Vue.prototype.$myMethod = function (methodOptions) {
        // 逻辑...
        console.log('myMethod')
      }
    }
    export default MyPlugin

    2、APP.vue文件

    <template>
    
    </template>
    <script>
        import Vue from 'vue'
        import MyPlugin from './myPlugin'
        Vue.use(MyPlugin)
        
        export default {
            data() {
                return {
                }
            },
            methods: {
            },
            mounted: function(){
                this.$myMethod();
                Vue.myGlobalMethod(); 
            }
        }
    </script>

    说明:以上两个文件位于同一目录

    组件注册完成,输出:

  • 相关阅读:
    hdoj_1556Color the ball
    wchar_t与char转换(总结)
    算法艺术——网络最大流
    poj_3268Silver Cow Party
    poj_2352Stars
    BellmanFord模板
    saas模式
    什么是管道
    什么是CMMI
    saas模式
  • 原文地址:https://www.cnblogs.com/mengfangui/p/9046525.html
Copyright © 2011-2022 走看看