【发布时间】:2017-06-11 17:45:01
【问题描述】:
我正在开发一个 vue.js 组件,我有这个计算属性:
loading_asset_status(){
var img = $("img.modal-main-image").attr('src', this.current_image.img_url)
.on('load', function() {
return (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0);
});
return img;
}
计算属性需要返回从加载函数返回的 true 或 false,但 img 变量包含 jQuery DOM 对象,而不是我想要的 true 或 false。所以这不起作用。
我也试过这个:
loading_asset_status(){
var status;
var img = $("img.modal-main-image").attr('src', this.current_image.img_url)
.on('load', function() {
status = (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0);
});
return status;
}
但是这个返回未定义。任何想法如何解决它?
【问题讨论】:
标签: javascript jquery vue.js