<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  </head>

  <body>
    <div id="app">
      <!-- v-bind -->
      <comp :cmessage="message" :cfruit="fruit"> </comp>
    </div>

    <template id="comp">
      <div id="">
        <p>{{cmessage}}</p>
        <ul>
          <li v-for="item in cfruit">{{item}}</li>
        </ul>
      </div>
    </template>

    <script>
      // 父传子 props
      const comp = Vue.extend({
        template: '#comp',
        props: ['cmessage', 'cfruit']
      })

      // root
      const app = new Vue({
        el: '#app',
        data: {
          message: 'Hello Vue.js!',
          fruit: ['苹果', '桃', '香蕉']
        },
        components: {
          comp,
        }
      })
    </script>
  </body>
</html>

vue父子组件通信_vue.js