vue + bootstrap 直接操作数据的列表清单的制作

 

 

<!DOCTYPE html>
<html>
<head>
   <meta charset="utf-8"> 
   <title>Bootstrap 实例 - 基本的表格</title>
   <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
   <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
   <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
   <script src="http://static.runoob.com/assets/vue/1.0.11/vue.min.js"></script>
</head>
<body>
   
   
   <div id="box">
         <div class="page-header">
           <h1 style="display: inline-block">{{name}}的购物清单列表</h1>
          <span>清单总数<span class="label label-warning">{{items.length}}</span></span>
            <span>未采购数<span class="label label-success">{{count}}</span></span>
         </div>
          <div class="panel">
        <div class="input-group">
          <input class="form-control" v-model="text" />
          <span class="input-group-btn"><button class="btn btn-default" @click="addItem(text)">添加</button></span>
        </div>
        <table class="table table-striped">
          <thead>
             <tr>
                <th>清单名称</th>
                <th>已采购</th>
                <th>状态</th>
                <th>删除</th>
             </tr>
          </thead>
          <tbody>
             <tr v-for="(index,item) in items">
                    <td>{{item.action}}</td>
                    <td><input type="checkbox" v-model="item.state" v-on:click="changelist()" /></td>
                    <td>{{item.state}}</td>
                    <td><button v-on:click="del(index)">删除</button></td>
             </tr>
          </tbody>
        </table>
   </div>
   </div>
   
<script type="text/javascript">
   window.οnlοad=function(){
        new Vue({
               el:"#box",
               data:{
                  name:"小朋友",
                  items:[
                  {action:"外套",state:false},
                  {action:"保暖衣",state:false},
                  {action:"夹克男士",state:true},
                  {action:"化妆品",state:false}
                  ],
                   text:'',
                   count:0
               },
               mounted:function(){ 
                  alert(1)
                  this.changelist()
               },
               methods:{
                  addItem:function(text){
                     if(text=="")return;
                     
                     this.items.push({action:text,state:false});
                     this.text='';
                     this.changelist()
                  },
                  changelist:function(){
                     
                     var _this = this;
                     _this.count=0;
                     this.items.forEach(function(element,index){
                        if(!element.state){
                           _this.count++;
                        }
                     })
                  },
                  del:function(index){
                  
                     if(this.items[index].state==true){
         
                        this.items.splice(index,1);
                     }
                  }
               }
              })
  
   }
            
    </script>
</body>
</html>

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值