created () {
this.$vux &&
this.$vux.bus &&
this.$vux.bus.$on('vux:after-view-enter',this.init)
},
init () {
const _this = this
this.blazy && this.blazy.destroy()
this.$el.src = this.defaultSrc
this.$el.className = this.$el.className.replace('b-loaded', '')
this.blazy = new Blazy({
scroller: this.scroller,
container: this.container,
selector: `#vux-ximg-${this.uuid}`,
offset: _this.offset,
errorClass: _this.errorClass,
successClass: _this.successClass,
success (ele) {
_this.$emit('on-success', _this.src, ele)
},
error (ele, msg) {
_this.$emit('on-error', _this.src, ele, msg)
}
})
},
mounted () {
this.$el.setAttribute('id', `vux-ximg-${this.uuid}`)
this.$nextTick(() => {
setTimeout(() => {
this.init()
}, this.delay)
})
detectWebp()
},
为什么这里要走两遍init方法,然后在demos页面时却只走了一遍on-successs事件