bootstrap Table插件可以很方便的搜索排序,方便快捷,下面是结合vue的完整的例子。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>Vue Bootstrap Table Demo</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../plugins/bootstrap-table-develop/src/bootstrap-table.css">
</head>

<body class="">
    <div>
        <table class="table table-bordered table-striped" id="tableTest1">
        </table>
    </div>
    <script src="../jQuery/jQuery-2.1.4.min.js"></script>
    <script src="../dist/vue.js"></script>
    <script src="../plugins/bootstrap-table-develop/src/bootstrap-table.js"></script>
    <script src="../plugins/bootstrap-table-develop/src/locale/bootstrap-table-zh-CN.js"></script>
    <script>
    var app7 = new Vue({
        el: '#tableTest1',
        data: {
            //message: [],
            message: [],
            columns: [{
                    title: 'Id',
                    field: 'id'
                },
                {
                    field: 'name',
                    title: 'Item Name'
                }, {
                    field: 'url',
                    title: 'url'
                }, {
                    field: 'alex',
                    title: 'alex'
                }, {
                    field: 'country',
                    title: 'country'
                }
            ],
        },
        created() {
            //console.log(this.message)
            this.getData();
            this.intervalGetData();
            //console.log(this.message)
        },

        methods: {
            intervalGetData() {
                setInterval(() => {
                    //      $.get("selectBtTable.php?action=init_data_list", data => {
                    //     var data = JSON.parse(data);
                    //     this.message = data;
                    //     $('#tableTest1').bootstrapTable('load', this.message);

                    //     //console.log(JSON.parse(data))
                    //     console.log("get data")
                    // })
                    this.getData();
                }, 3000)

            },
            getData() {
                //es6 箭头函数的写法
                //    $.get("selectBtTable.php?action=init_data_list", data => {
                //     var data = JSON.parse(data);
                //     this.message = data;
                //     $('#tableTest1').bootstrapTable('load', this.message);
                //     console.log("init data")
                // })
                var that = this;
                $.get("selectBtTable.php?action=init_data_list", function(data) {
                    var data = JSON.parse(data);
                    that.message = data;
                    $('#tableTest1').bootstrapTable('load', that.message);
                    console.log("init data")
                })
            }
        },
        mounted() {
            console.log(this.message + "mounted")
            $('#tableTest1').bootstrapTable({ columns: this.columns, height: 500, search: true });
        }

    })
    </script>
</body>

</html>

 

转载于:https://my.oschina.net/u/2612473/blog/1594917

Logo

前往低代码交流专区

更多推荐