如何掌握vue中install方法,要点是什么
这篇文章主要介绍“如何掌握vue中install方法,要点是什么”,有一些人在如何掌握vue中install方法,要点是什么的问题上存在疑惑,接下来小编就给大家来介绍一下相关的内容,希望对大家解答有帮助,有这个方面学习需要的朋友就继续往下看吧。
关于“如何掌握vue中install方法,要点是什么”就介绍到这了,如果大家觉得不错可以参考了解看看,如果想要了解更多,欢迎关注博信,小编每天都会为大家更新不同的知识。
目录
1、全局注册组件 2、全局自定义指令vue
提供install
可供我们开发新的插件及全局注册组件等
install
方法第一个参数是vue
的构造器,第二个参数是可选的选项对象
export default { install(Vue,option){ 组件 指令 混入 挂载vue原型 } }
1、全局注册组件
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)
2、全局自定义指令
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方法,要点是什么”就介绍到这了,如果大家觉得不错可以参考了解看看,如果想要了解更多,欢迎关注博信,小编每天都会为大家更新不同的知识。
版权声明
本文仅代表作者观点,不代表博信信息网立场。