props 條件驗證

在Vue中父組件向子組件中傳送數據是通過props實現的,一個簡單的使用props的例子:

 <!DOCTYPE html>
  <html>
  <head>
      <meta charset="utf-8">
      <title>Vue Study</title>
  </head>
  <body>  
     <div id="app">
         <foo-component :foo-message="fooMessage"></foo-component>  
     </div>
  
 <script type="text/javascript" src="lib/vue.js"></script>
 <script type="text/javascript">
  
     var fooComponent = {
         props: ['fooMessage'],
         template: '<div> {{ fooMessage }} </div>'
     };
  
     var vm = new Vue({
         components: {
             'foo-component': fooComponent
         },
        el: '#app',
        data: {
             fooMessage: 123
         }
     });
 
</script>
 </body>
 </html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章