vuejs scope

<!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></parent>
</div>
 
<script>

Vue.component('child', {
  // 有效,因为是在正确的作用域内
  template: '<div class="child">  <slot text="hello from child"></slot></div>',
  data: function () {
    return {
      someChildProperty: true
    }
  }
})




Vue.component('parent', {
  // 有效,因为是在正确的作用域内
  template:'<div class="parent">  <child>    <template scope="props">      <span>hello from parent</span>  <br>    <span>{{ props.text }}</span>    </template>  </child></div>',
  data: function () {
    return {
      someChildProperty: true
    }
  }
})




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


</script>



</body>
</html>

 

posted on 2017-03-21 17:11  rojas  阅读(214)  评论(0编辑  收藏  举报