vue 通過 Prop 向子組件傳遞數(shù)據(jù)的實現(xiàn)方法
這是一個通過 Prop 向子組件傳遞數(shù)據(jù)的小例子。
代碼:
<!DOCTYPE html><html lang='zh-cmn-Hans'> <head> <meta charset='UTF-8'> <title></title> <style> *{margin: 0;padding: 0;text-decoration: none; } </style> </head> <body> <div id='app'> <!--數(shù)據(jù)的渲染--> <ul><student-component v-for='item in students' :student='item'></student-component> </ul> </div> <script src='http://www.aoyou183.cn/vue.js'></script> <script> //子組件 //編寫學生組件 Vue.component(’student-component’,{props:[’student’], // props 可以是數(shù)組或?qū)ο螅糜诮邮諄碜愿附M件的數(shù)據(jù)。template:`<li> <h3>學生的姓名:{{student.name}}</h3> <h3>學生的年齡:{{student.age}}</h3> <h3>學生的興趣:{{student.hobbies}}</h3> <hr/> <br/> </li>` }) //父組件 let app = new Vue({el:’#app’,data:{ //把這些數(shù)據(jù)傳給子組件 然后渲染到頁面上 students:[ { name:’丁七歲’, age:19, hobbies:’吃飯 睡覺 打豆豆’ }, { name:’丁七歲2’, age:19, hobbies:’吃飯 睡覺 打豆豆’ }, { name:’丁七歲3’, age:19, hobbies:’吃飯 睡覺 打豆豆’ } ,{ name:’丁七歲4’, age:19, hobbies:’吃飯 睡覺 打豆豆’ } ]} }) </script> </body></html>
不再關心dom操作了 專注于數(shù)據(jù)的渲染。比如這個關注點 就是如何把 students這個數(shù)組中的信息渲染到頁面上給用戶看。
到此這篇關于vue 通過 Prop 向子組件傳遞數(shù)據(jù)的實現(xiàn)方法的文章就介紹到這了,更多相關vue Prop子組件傳遞數(shù)據(jù)內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網(wǎng)!
相關文章:
1. 基于javascript處理二進制圖片流過程詳解2. 解決android studio引用遠程倉庫下載慢(JCenter下載慢)3. Gitlab CI-CD自動化部署SpringBoot項目的方法步驟4. ajax請求添加自定義header參數(shù)代碼5. ASP基礎知識VBScript基本元素講解6. 使用Python和百度語音識別生成視頻字幕的實現(xiàn)7. Kotlin + Flow 實現(xiàn)Android 應用初始化任務啟動庫8. idea刪除項目的操作方法9. 教你如何寫出可維護的JS代碼10. 使用python 計算百分位數(shù)實現(xiàn)數(shù)據(jù)分箱代碼
