這篇文章將為大家詳細(xì)講解有關(guān)Vue中組件模板怎么用,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

1. vue組件都是由這三部分組成
<template>
<div>
</div>
</template>
<script>
export default{}
</script>
<style>
</style>2. 組件間的引用
分3步走,假設(shè)現(xiàn)在有兩個(gè)組件 App.vue,和 Add.vue,現(xiàn)在要把Add.vue組件引入到App.vue組件中
App.vue
<template>
// 第3步
<Add/>
</template>
<script>
// 第1步
import Add from './components/Add.vue'
// 第2步
components: {
Add
}
}
</script>
<style>
</style>3. 組件間數(shù)據(jù)的傳遞
假將要將App.vue組件中的數(shù)據(jù)傳遞到Ad.vue組件中
App.vue
<template>
// 第3步
// 傳遞數(shù)據(jù),注意冒號(hào)
<Add :comments="comments"/>
</template>
<script>
// 第1步
import Add from './components/Add.vue'
// 第2步
components: {
Add
},
// App組件中初始化的數(shù)據(jù)
data(){
return {
comments: [{
name: 'Bob',
content: 'Vue 還不錯(cuò)'
}, {
name: 'Cat',
content: 'Vue so Easy'
}, {
name: 'BZ',
content: 'Vue so so'
}
]
}
}
}
</script>
<style>
</style>Add.vue
<script>
export default{
// 聲明接收comments數(shù)據(jù)
props: ['comments']
}
</script>關(guān)于“Vue中組件模板怎么用”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
本文標(biāo)題:Vue中組件模板怎么用-創(chuàng)新互聯(lián)
當(dāng)前URL:http://www.chinadenli.net/article6/dcheog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、手機(jī)網(wǎng)站建設(shè)、App開發(fā)、用戶體驗(yàn)、動(dòng)態(tài)網(wǎng)站、全網(wǎng)營銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容