• vue day7 table checkbox 全选


     
    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>分页</title>
            <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
        <script type="text/javascript" src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
    
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    
    </head>
    <body>
    
        <div id="app-4" class="col-xs-12 main-table-wrapper">
            <table class="table table-striped table-hover table-bordered" id="main-table">
                <thead>
                    <tr>
                        <th><input type="checkbox" v-model="checkall"  v-on:click='checkAll'></th>
                        <th>商品名称</th>
                        <th>商品单价</th>
                        <th>数量</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item,index) in tableData">
                        <td><input type="checkbox" v-model="checked" :value="item.id"  />   </td>
                        <td>{{ item.name }}</td>
                        <td>{{ item.address }}</td>
                        <td>{{ item.date }}</td>
                        <td><button @click="handleRemove(index)">移除</button></td>
    
                    </tr>
    
    
                </tbody>
            </table>
            <div>{{checked}}</div>
        </div>  
    
    
        
        <script>
    
    
    
    
    
            var app = new Vue({
                el: '#app-4',
                data: {
                    tableData: [{
                        id:1,
                        date: '2016-05-02',
                        name: '王小虎',
                        address: '上海市普陀区金沙江路 1518 弄',
    
                        }, {
                            id:2,
                            date: '2016-05-04',
                            name: '王小虎',
                            address: '上海市普陀区金沙江路 1517 弄'
                        }, {
                            id:3,
                            date: '2016-05-01',
                            name: '王小虎',
                            address: '上海市普陀区金沙江路 1519 弄'
                        }, {
                            id:4,
                            date: '2016-05-03',
                            name: '王小虎',
                            address: '上海市普陀区金沙江路 1516 弄'
                        }
                    ],
                    checkall:false,
                    checked:[]
                },
                methods: {
                    handleRemove: function(index){
                            this.tableData.splice(index,1);
                        },
                    checkAll: function () {
                        var _this = this
                        if (this.checkall) {
                        // 实现反选
                            this.checked = []
                        } else {
                        // 实现全选
                            this.checked = []
                            this.tableData.forEach(function (item) {
                                _this.checked.push(item.id)
                            })
                        }
                        if (this.checked.length === this.tableData.length) {
                            this.checkall = true
                        // console.log(this.checkall)
                        // console.log(this.checked)
                        } 
                    }
                }
            });
    
    
     
    
        </script>
    </body>
    </html>
  • 相关阅读:
    iostream迭代器操作"txt文本文件"无法写入的思考
    Qt 相对路径 绝对路径
    "lambda"和“bind”的初步思考
    "partition"和“stable_partition”的思考
    "accumulate"的思考
    顺序容器“inset”的思考
    C++重载函数 const形参 引用指针 const_cast
    C++ 可变参数的函数
    JDK8流式处理常用例子
    JDK8时间新API
  • 原文地址:https://www.cnblogs.com/LiuFengH/p/10657451.html
Copyright © 2020-2023  润新知