【发布时间】:2015-11-23 16:17:53
【问题描述】:
我有一个ladda按钮如下。
<button class="btn btn-primary btn-xs ladda-button"
data-style="slide-left" data-size="xs" v-on:click="refreshPage()">Refresh</button>
VueJs 负责触发onClick 事件。单击按钮时会调用以下功能
refreshPage: function() {
that = this;
Ladda.bind( '.ladda-button', {
callback: function( instance ) {
instance.start();
console.log(this);
that.getProjectEvents();
that.getIgnoredEvents();
toastr.info('Refresh was done.');
instance.stop();
}
} );
}
getProjectEvents 代码如下
getProjectEvents: function() {
this.$http.get('/project/exceptions/'+url(-1)).success(function(response) {
this.$set('events', response);
});
},
getIgnoredEvents如下
getIgnoredEvents : function() {
this.$http.get('/exceptions/ignoredExceptions/'+ url(-1)).success(function(response) {
this.$set('ignoredExceptions', response);
});
},
getProjectEvents 和 getIgnoredEvents 都定义在同一个 JS 文件中。
问题
当我单击按钮时,没有显示微调器。但是,当我从两种方法(getProjectEvents 和 getIgnoredEvents)中提取代码并放入回调时,一切都开始工作了。我想知道为什么当我调用函数时它没有被调用!
我也尝试使用 setTimeOut 函数(想知道刷新是否发生得太快)但它不起作用(显然是因为它是异步的)。
你能告诉我我在这里做错了什么吗?
谢谢
【问题讨论】:
-
您是否在控制台中收到任何错误消息?
标签: javascript jquery vue.js