vuejs fatherandson

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>vue</title>

     <!-- 
    <script src="vue.js"></script>
    -->
    
 <script src="https://unpkg.com/vue/dist/vue.js"></script>
 
</head>
<body> 
 
 <div id="counter-event-example">
  <parent-component></parent-component>
</div>
 
<script>

Vue.component('child-component', {
  // 有效,因为是在正确的作用域内
  template: '<div>  <h2>我是子组件的标题</h2>  <slot name="content1">    只有在没有要分发的内容时才会显示。  </slot><slot name="content2"></slot>  </div>',
  data: function () {
    return {
      someChildProperty: true
    }
  }
})




Vue.component('parent-component', {
  // 有效,因为是在正确的作用域内
  template: '<div>  <h1>我是父组件的标题</h1>  <child-component>    <p slot="content1">这是一些初始内容</p>    <p slot="content2">这是更多的初始内容</p>  <p> 这个不会显示</p> </child-component></div>',
  data: function () {
    return {
      someChildProperty: true
    }
  }
})

new Vue({
  el: '#counter-event-example'
})


</script>



</body>
</html>
原文地址:https://www.cnblogs.com/rojas/p/6595474.html