vue v-for 绑定数据

<!DOCTYPE html>
<html>
 <meta charset="utf-8">
<head>
    <title></title>
</head>
<script src="./vue.js" type="text/javascript" charset="utf-8"></script>
<body>
<div id="app">
    <input type="button" name="" value='添加' v-on:click='add'>
    <p v-for="(val,i) in list" :key='val.id'>
        <input type="checkbox" name="">
        {{val.id}}--------{{val.name}}
    </p>
</div>
<script type="text/javascript">
  var vm = new Vue({
       el:'#app',
       data:{       
           list:[
               {id:1,name:'cheng'},
               {id:2,name:'feng'},
               {id:3,name:'chi'},
           ]
       },
       methods:{
           add:function(){
               this.list.unshift({id:4,name:'wang'})
           }
       }
   })
</script>
</body>
</html>

 

posted @ 2019-08-12 10:27  酷酷的城池  阅读(1732)  评论(0编辑  收藏  举报