使用-Prop-傳遞數據(父組件通過 props 向下傳遞數據給子組件)
阿新 • • 發佈:2017-07-04
log ssa nbsp vue.js app charset oct 傳遞數據 spa
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>使用-Prop-傳遞數據</title> <script src="vue.js"></script> </head> <body> <div id="app"> <!--傳入值到子模板的props--> <child my-message="hello!"></child> <!--綁定父組件的數據到子模板的props--> <child2 v-bind:cm="parentMsg"></child2> </div> <script> Vue.component(‘child‘, { props : [‘myMessage‘], template : ‘<span>{{ myMessage }}</span>‘ }) Vue.component(‘child2‘, { props : [‘cm‘], template : ‘<span>{{ cm }}</span>‘ }) new Vue({ el : ‘#app‘, data : { parentMsg : ‘parentMsg‘ } }) </script> </body> </html>
使用-Prop-傳遞數據(父組件通過 props 向下傳遞數據給子組件)