Vue中的局部組件介紹
更新時間:2022年01月24日 14:25:22 作者:huxiaoxiao.
這篇文章主要介紹了Vue中的局部組件,文章圍繞Vue局部組件得相關資料展開內(nèi)容,需要的的小孩伙伴請參考下面文章的具體介紹,希望對你有所幫助
在Vue中我們可以自己定義(注冊)局部組件
定義組件名的方式:
var ComponentA = { /* ... */ } var ComponentB = { /* ... */ }
然后在 components 選項中定義你想要使用的組件:
new Vue({ el: '#app', // 組件中心 components: { // 在視圖層渲染 局部注冊組件時 // component-a:你要在視圖層調(diào)用時使用的名稱 // ComponentA: 局部注冊組件名稱 'component-a': ComponentA, 'component-b': ComponentB } })
在視圖層調(diào)用局部組件:
<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回調(diào)函數(shù)change的參數(shù)問題
今天小編就為大家分享一篇淺談ElementUI中switch回調(diào)函數(shù)change的參數(shù)問題,具有很好的價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08vue 數(shù)組和對象不能直接賦值情況和解決方法(推薦)
這篇文章主要介紹了vue 數(shù)組和對象不能直接賦值情況和解決方法,需要的朋友可以參考下2017-10-10