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>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章:
1. 詳解Android studio 動態fragment的用法2. 編程語言PHP在Web開發領域的優勢在哪?3. 什么是python的自省4. Spring Boot和Thymeleaf整合結合JPA實現分頁效果(實例代碼)5. 解決Android studio xml界面無法預覽問題6. 基于android studio的layout的xml文件的創建方式7. Android如何加載Base64編碼格式圖片8. Springboot Druid 自定義加密數據庫密碼的幾種方案9. Vue封裝一個TodoList的案例與瀏覽器本地緩存的應用實現10. 圖文詳解vue中proto文件的函數調用

網公網安備