【发布时间】:2016-03-09 07:38:22
【问题描述】:
我已将 bootstrapTable (https://github.com/wenzhixin/bootstrap-table) 包装到指令中,如下所示:
Vue.directive('bootstraptable', {
priority: 1000,
params: ['url', 'resource-name'],
bind: function () {
var _self = this;
$(this.el)
.bootstrapTable({
pagination: true,
pageSize: 15,
pageList: [],
sidePagination: 'server',
url: this.params.url,
queryParams: function (params) {
return params;
},
cookie: true,
cookieExpire: '24h',
cookieIdTable: this.params.resourceName + '-table',
locale: 'it-IT'
}).on('load-success.bs.table', function (e, data) {
$('[data-toggle="tooltip"]').tooltip();
_self.vm.$compile(_self.vm.$el);
});
},
update: function (value) {
$(this.el).val(value)
},
unbind: function () {
$(this.el).off().bootstrapTable('destroy')
}
});
从服务器返回的 JSON 包含一个带有 v-on 指令的按钮,因此我必须重新编译注入的 HTML 行以使按钮指令正常工作。 无论如何,下面的代码似乎不起作用:
_self.vm.$compile(_self.vm.$el);
我是否遗漏了一些明显的东西?
【问题讨论】:
-
你试过
$mount吗? -
组件已经挂载,事实上,如果我调用
$mount,这就是我得到的:[Vue warn]: $mount() should be called only once.
标签: javascript vue.js bootstrap-table