自定义组件进行全局注册
在学习Vue中,由于想把自定义组件进行全局使用,但组件过多导致main.js中内容过长,理解其原理,类似按需导入的方式注册全局组件。
👉阿勇的博客👈
-
在
components目录下新建index.js -
导入已经写好的自定义组件
-
import OneDialog from './Dialog/index.vue'
-
-
对自定义组件进行全局注册
-
const customize = { install(Vue) { Vue.component('OneDialog', OneDialog) } } export default customize
-
-
在
main.js中进行导入-
import customize from './components/index' Vue.use(customize)
-
-
.vue文件中进行使用

浙公网安备 33010602011771号