我是靠谱客的博主 暴躁故事,这篇文章主要介绍Vue.component封装组件并注册使用,现在分享给大家,希望可以做个参考。

1.ConterContainer.vue

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<template> <div class="conterContainer"> <slot></slot> </div> </template> <script> export default {}; </script> <style> .conterContainer { display: flex; display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; /* 子元素水平居中 */ -webkit-justify-content: center; justify-content: center; -moz-box-pack: center; } </style>

2.index.js

复制代码
1
2
3
4
5
6
7
import ConterContainer from './components/ConterContainer.vue' export default { install: (Vue) => { Vue.component('ConterContainer', ConterContainer) } }

3.main.js

复制代码
1
2
3
import Plugin from '@/plugin/index.js'; Vue.use(Plugin);

4.可以直接在vue组件中使用了

复制代码
1
2
3
4
5
6
7
8
9
<template> <ConterContainer> <h2></h2> </ConterContainer> </template> <script> export default {}; </script>

最后

以上就是暴躁故事最近收集整理的关于Vue.component封装组件并注册使用的全部内容,更多相关Vue内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

评论列表共有 0 条评论

立即
投稿
返回
顶部