vue
提供install
可供我们开发新的插件及全局注册组件等
install
方法第一个参数是vue
的构造器,第二个参数是可选的选项对象
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15export default { install(Vue,option){ 组件 指令 混入 挂载vue原型 } }
1、全局注册组件
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31import 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进行注册
复制代码
1
2
3import Component from '@/components' Vue.use(Component)
2、全局自定义指令
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31export 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跟注册组件一样
复制代码
1
2
3import pre from '@/aiqi' Vue.use(pre)
到此这篇关于 vue中install方法介绍的文章就介绍到这了,更多相关 vue中install方法内容请搜索靠谱客以前的文章或继续浏览下面的相关文章希望大家以后多多支持靠谱客!
最后
以上就是多情高山最近收集整理的关于vue中install方法介绍的全部内容,更多相关vue中install方法介绍内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复