引导数据表和vue

时间:2018-03-05 09:29:18

标签: twitter-bootstrap vue.js

我使用bootstrap数据表和vue.js和 当我尝试在vue模型创建后调用DataTable函数时,它不起作用,为什么? 我也尝试了$(app。$ el).datatable(),但没有用。 这是我的代码

<table id="example" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
  <thead>
    <tr>
      <th class="all">First name</th>
      <th class="desktop">Last name</th>
    </tr>
  </thead>
  <tbody>
    <tr v-for="ws in workschedule">
      <td>test</td>
      <td>test</td>
    </tr>
  </tbody>
</table>
$(document)
    .ready(function () {
            var app = new Vue({
                el: '#example',
                data: {
                    workschedule: []
        },
                created: function () {
                this.getSchedule();
            },
            methods: {
                getSchedule: function() {
                    var autourl =
                        'get.aspx?op=json&table=StoreUserWorkSchedule&qd=storeuserworkschedule' + appendTime();
                    this.$http.get(autourl)
                        .then(function(response) {
                            this.workschedule = response.data;
                        });
                }
            }
            });
            $('#example').DataTable({
            responsive: true
        });

    });

2 个答案:

答案 0 :(得分:1)

您正尝试在创建的挂钩中访问$el属性。在安装vue实例后,$el挂钩,可以使用mounted: function() { this.$el.DataTable({ responsive: true }); }

因此,在挂载的挂钩

中调用数据表函数
dojox/mobile/View

答案 1 :(得分:0)

最后,watch选项解决了它

            var app = new Vue({
                el: '#example',
                data: {
                    workschedule: []
                },
                created: function () {
                    this.getSchedule();
                },
                watch: {
                    workschedule: function (newData) {
                        $('#example').DataTable({
                            responsive: true
                        });
                    }
            },
            methods: {
                getSchedule: function() {
                    var autourl =
                        'get.aspx?op=json&table=StoreUserWorkSchedule&qd=storeuserworkschedule' + appendTime();
                    this.$http.get(autourl)
                        .then(function(response) {
                            this.workschedule = response.data;
                        });
                }
            }
            });