zoukankan      html  css  js  c++  java
  • vue中install方法

     

    vue提供install可供我们开发新的插件及全局注册组件等
    install方法第一个参数是vue的构造器,第二个参数是可选的选项对象

    export default {
        install(Vue,option){
            组件
            指令
            混入
            挂载vue原型
        }
    }

    全局注册组件

    import PageTools from '@/components/PageTools/pageTools.vue'
    import update from './update/index.vue'
    import ImageUpload from './ImageUpload/ImageUpload.vue'
    import ScreenFull from './ScreenFull'
    import ThemePicker from './ThemePicker'
    import TagsView from './TagsView'
    export default {
      install(Vue) {
        Vue.component('PageTools', PageTools)
        Vue.component('update', update)
        Vue.component('ImageUpload', ImageUpload)
        Vue.component('ScreenFull', ScreenFull)
        Vue.component('ThemePicker', ThemePicker)
        Vue.component('TagsView', TagsView)
      }
    }

    在main.js中直接用引用并Vue.use进行注册

    import Component from '@/components'
    Vue.use(Component)

    全局自定义指令

    export default{
        install(Vue){
            Vue.directive('pre',{
                inserted(button,bind){
                    button.addEventListener('click',()=>{
                        if(!button.disabled){
                            button.disabled = true;
                            setTimeout(()=>{
                                button.disabled = false
                            },1000)
                        }
                    })
                }
            })
        }
    }

    在main.js跟注册组件一样

    import pre from '@/aiqi'
    
    Vue.use(pre)

    全局注册,任何地方可用。

    本文链接:vue中install方法_曾泳锋的博客-CSDN博客icon-default.png?t=LA92https://blog.csdn.net/weixin_44795287/article/details/113877107

  • 相关阅读:
    Best code水题之路
    我的CodeF水A题之路
    studing(来自转载)
    BFS
    fibonacci数列(五种)
    Redis阻塞队列原理学习
    the enum hack
    Divide Two Integers
    Surrounded Regions
    Search in Rotated Sorted Array
  • 原文地址:https://www.cnblogs.com/onesea/p/15702187.html
Copyright © 2011-2022 走看看