這篇文章主要介紹了Vue中組件模板如何用的相關知識,內容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇Vue中組件模板如何用文章都會有所收獲,下面我們一起來看看吧。
1. vue組件都是由這三部分組成
<template>
<div>
</div>
</template>
<script>
export default{}
</script>
<style>
</style>2. 組件間的引用
分3步走,假設現在有兩個組件 App.vue,和 Add.vue,現在要把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. 組件間數據的傳遞
假將要將App.vue組件中的數據傳遞到Ad.vue組件中
App.vue
<template>
// 第3步
// 傳遞數據,注意冒號
<Add :comments="comments"/>
</template>
<script>
// 第1步
import Add from './components/Add.vue'
// 第2步
components: {
Add
},
// App組件中初始化的數據
data(){
return {
comments: [{
name: 'Bob',
content: 'Vue 還不錯'
}, {
name: 'Cat',
content: 'Vue so Easy'
}, {
name: 'BZ',
content: 'Vue so so'
}
]
}
}
}
</script>
<style>
</style>Add.vue
<script>
export default{
// 聲明接收comments數據
props: ['comments']
}
</script>關于“Vue中組件模板如何用”這篇文章的內容就介紹到這里,感謝各位的閱讀!相信大家對“Vue中組件模板如何用”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。