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ù)組或對象,用于接收來自父組件的數(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ù)內容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網(wǎng)!
相關文章:
1. ASP動態(tài)網(wǎng)頁制作技術經(jīng)驗分享2. jsp文件下載功能實現(xiàn)代碼3. asp.net core項目授權流程詳解4. 在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法5. CSS3實現(xiàn)動態(tài)翻牌效果 仿百度貼吧3D翻牌一次動畫特效6. XMLHTTP資料7. ASP常用日期格式化函數(shù) FormatDate()8. html中的form不提交(排除)某些input 原創(chuàng)9. CSS3中Transition屬性詳解以及示例分享10. ASP基礎入門第八篇(ASP內建對象Application和Session)
