045——VUE中组件之父组件使用scope定义子组件模板结构

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>组件之父组件使用scope定义子组件模板结构</title>
    <script src="vue.js"></script>
</head>

<body>

<div id="hdcms">
    <hd-list :data="news">
        <template scope="v">
            <li>
                <h1>{{v.field.title}}</h1>
            </li>
        </template>
    </hd-list>
</div>
<script typeof="text/x-template" id="hdList">
    <ul>
        <slot v-for="v in data" :field="v"></slot>
    </ul>
</script>
<script>
    var hdList = {
        template: "#hdList",
        props:['data']
    };
    new Vue({
        el: "#hdcms",
        components: {hdList},
        data:{
            news:[
                {title:'phpjava'},
                {title:"课程学习"}
            ]
        }
    });
</script>

</body>

</html>

  

posted @ 2018-01-09 16:43  生如逆旅,一苇以航  阅读(434)  评论(0编辑  收藏  举报