1. 程式人生 > >元件(vue練習例子)

元件(vue練習例子)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        [v-cloak]{display: none;}
    </style>
</head>
<body>
<div id="app">
    <my-component-list :datalist="list"></my-component-list>
</div>
<script src="https://cdn.bootcss.com/vue/2.5.13/vue.js"></script>
<script type="text/javascript">
new Vue({
    el:"#app",
    data:{
        list:[{
            name:"肖申克救贖",
            year:1994
        },{
            name:"霸王別姬",
            year:1993
        },{
            name:"這個殺手不太冷",
            year:1994
        },{
            name:"阿甘正傳",
            year:1994
        },{
            name:"美麗人生",
            year:1997
        },{
            name:"千與千尋",
            year:2001
        },{
            name:"辛德勒的名單",
            year:1993
        },{
            name:"泰坦尼克號",
            year:1997
        },{
            name:"盜夢空間",
            year:2010
        },{
            name:"機器人總動員",
            year:2008
        }]
    },
    //區域性註冊
    components:{
        "my-component-list":{
            template:'<ul><li v-for="item in datalist">{{item.name}}<span>[{{item.year}}年]</span></li></ul>',
            props:["datalist"]
        }
    }
})
</script>
</body>
</html>