vue中install方法介紹
vue
提供install
可供我們開發(fā)新的插件及全局注冊組件等
install
方法第一個參數(shù)是vue
的構(gòu)造器,第二個參數(shù)是可選的選項對象
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進(jìn)行注冊
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)
到此這篇關(guān)于 vue中install方法介紹的文章就介紹到這了,更多相關(guān) vue中install方法內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue3實現(xiàn)LuckSheet在線預(yù)覽Excel表格
在前端開發(fā)中預(yù)覽Excel文件是常見的需求之一,本文將介紹如何使用Vue.js框架以及兩個優(yōu)秀的Excel庫——LuckyExcel和Luckysheet,來實現(xiàn)Excel文件在線預(yù)覽功能,希望對大家有所幫助2023-11-11Vue3+Antd實現(xiàn)彈框顯示內(nèi)容并加入復(fù)制按鈕
這篇文章主要介紹了Vue3+Antd實現(xiàn)彈框顯示內(nèi)容并加入復(fù)制按鈕,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2023-12-12vue日常開發(fā)基礎(chǔ)Axios網(wǎng)絡(luò)庫封裝
這篇文章主要為大家介紹了vue日常開發(fā)基礎(chǔ)Axios網(wǎng)絡(luò)庫封裝示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08