自定义组件

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>test</title>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    </head>
    <body>
        <div id="myspan">
            <ul>
                <component-li v-for="li in lists" v-bind:item="li"></component-li>
            </ul>
        </div>
    </body>
    <script>
        Vue.component("component-li",{
            props:["item"],
            template:"<li>{{item}}</li>"
        })
    
        var vue = new Vue({
            el:"#myspan",
            data:{
                lists:[]
                },
                mounted() {
                    axios.get("data.json")
                    .then(response=>this.lists=response.data)
                }
        })
    </script>
</html>

 

posted @ 2021-04-11 13:15  动力起点  阅读(31)  评论(0编辑  收藏  举报