slot作用域插槽

2019-04-01  本文已影响0人  如果俞天阳会飞
<body>
<div id="app">
    <div>
        <heading :lists="direction">
            <!--  这里 的  slot-scope 是 2.5 版本的  使用之前 版本的会报错 -->
            <template slot-scope="scope">
                <span>{{scope}}</span>
                <p v-for="(item,key) in scope.sign" :key="key" :href="item.hrefs">{{item.name}}</p>
            </template>
        </heading>
    </div>
</div>
<script>
  Vue.component("heading", {
    props: {
      lists: {
        type: Array
      }
    },
    template: `<div>
                 <slot :sign ="lists"></slot>
             </div>`

  });
  new Vue({
    el: '#app',
    data: {
      direction: [
{name: 'a', href: 'www.baidu.com'},
 {name: 'b', href: 'www.taobao.com'}
]
    }
  });
</script>
</body>
上一篇 下一篇

猜你喜欢

热点阅读