鍍金池/ 問答/HTML/ vue 如何動態(tài)切換全局的placeholder圖片

vue 如何動態(tài)切換全局的placeholder圖片

我在assets中存儲了各主題對應的placeholder文件,想通過eventbus和全局mixin動態(tài)更換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是''還是' '

2017年11月2日 07:03