我在assets中存储了各主题对应的placeholder文件,想通过eventbus和全局mixin动态更换placeholder图片,虽然app.vue中的placeHolderNothing改变了,但是img的src并没有值,为什么?
<img :src="imgUrl||placeHolderNothing"/>
App.vue
created () {
bus.$on('changeTheme', (themeId) => {
themeId = +themeId
let theme = 'purple'
switch (themeId) {
case 1:
theme = 'purple'
break
case 2:
theme = 'red'
break
case 3:
theme = 'blue'
break
default:
theme = 'purple'
}
this.placeHolderNothing = require(`@/assets/icon_nothing_${theme}.svg`)
})
Vue.mixin({
data () {
return {
placeHolderNothing: this.placeHolderNothing
}
}
})
切换主题时
bus.$emit('changeTheme', this.themeId)
检查一下imgUrl是''还是' '