UNPKG

rax-image

Version:
79 lines (78 loc) 1.96 kB
import fmtEvent from './fmtEvent'; console.warn('组件所依赖的 rax-image 版本较旧,请尽快重新构建发布该组件'); Component({ data: { style: '' }, properties: { className: { type: String, value: '' }, styleSheet: { type: String, value: '' }, mode: { type: String, value: 'scaleToFill' }, source: { type: Object, value: { uri: '' } }, lazyLoad: { type: Boolean, value: false }, loading: { type: String, value: 'eager' } }, lifetimes: { attached: function attached() { this.initImage(); } }, observers: { styleSheet: function styleSheet(newStyleSheet) { this.initImage('styleSheet', newStyleSheet); }, source: function source(newSource) { this.initImage('source', newSource); } }, options: { styleIsolation: 'apply-shared' }, methods: { onError: function onError(e) { var event = fmtEvent(this.properties, e); this.triggerEvent('onError', event.detail); }, onLoad: function onLoad(e) { var event = fmtEvent(this.properties, e); this.triggerEvent('onLoad', event.detail); }, onTap: function onTap(e) { var event = fmtEvent(this.properties, e); this.triggerEvent('onClick', event.detail); }, initImage: function initImage(type, newValue) { var _ref = (type === 'source' ? newValue : this.properties.source) || {}, _ref$width = _ref.width, width = _ref$width === void 0 ? null : _ref$width, _ref$height = _ref.height, height = _ref$height === void 0 ? null : _ref$height; var style = type === 'styleSheet' ? newValue : this.properties.styleSheet || ''; if (width) style += 'width:' + width + 'rpx;'; if (height) style += 'height:' + height + 'rpx;'; this.setData({ style: style }); } } });