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>

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

    组件注册完成,输出:

  • 相关阅读:
    poj 1562 Oil Deposits
    poj 1650 Integer Approximation
    snmp4j 编程
    ubuntu 13.04 163源(亲测可用)
    c语言中static 用法总结(转)
    Spring入门
    Hibernate入门
    Struts2入门教程
    素数距离问题
    ASCII码排序
  • 原文地址:https://www.cnblogs.com/mengfangui/p/9046525.html
Copyright © 2011-2022 走看看