Vue中的局部组件介绍
更新时间:2022年01月24日 14:25:22 作者:huxiaoxiao.
这篇文章主要介绍了Vue中的局部组件,文章围绕Vue局部组件得相关资料展开内容,需要的的小孩伙伴请参考下面文章的具体介绍,希望对你有所帮助
在Vue中我们可以自己定义(注册)局部组件
定义组件名的方式:
var ComponentA = { /* ... */ } var ComponentB = { /* ... */ }
然后在 components 选项中定义你想要使用的组件:
new Vue({ el: '#app', // 组件中心 components: { // 在视图层渲染 局部注册组件时 // component-a:你要在视图层调用时使用的名称 // ComponentA: 局部注册组件名称 'component-a': ComponentA, 'component-b': ComponentB } })
在视图层调用局部组件:
<div id="app"> <component-a></component-a> <component-b></component-b> </div>
举个列子:
<body> <div id="app"> <component-a></component-a> <component-b></component-b> </div> <script src="./js/vue.js"></script> <script> let componentA = { template:` <p>我是局部组件1</p> ` } let componentB = { template:` <p>我是局部组件2</p> ` } let vm = new Vue({ el:'#app', data:{ }, components:{ "component-a":componentA, "component-b":componentB } }) </script>
输出结果为:
相关文章
Vue3+Vite项目引入Bootstrap5、bootstrap-icons方式
这篇文章主要介绍了Vue3+Vite项目引入Bootstrap5、bootstrap-icons方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2023-10-10浅谈ElementUI中switch回调函数change的参数问题
今天小编就为大家分享一篇浅谈ElementUI中switch回调函数change的参数问题,具有很好的价值,希望对大家有所帮助。一起跟随小编过来看看吧2018-08-08
最新评论