如何在vue模版的属性里使用 vuex 的 store 的值?

这是vuex官网给出的示例,很容易理解

const Counter = { 
 template: `<div>{{ count }}</div>`,  computed: {
    count () {    
      return store.state.count
    }
    
  }
}

我现在想在html的属性里使用count,如

const Counter = { 
 template: `<img src="{{img}}">`,  computed: {
    count () { 
         return store.state.img
    }
  }
}

但是这么写是不行的,请问如过要实现这种效果该怎么实现呢?


慕少森
浏览 5291回答 2
2回答

万千封印

只要用到vue实例中的数据,在html中的属性前都要使用:绑定

翻过高山走不出你

用 :src="$store.state.img" 或者 :src="count"
打开App,查看更多内容
随时随地看视频慕课网APP