绑定img src [英] Binding img src

查看:32
本文介绍了绑定img src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个 Vue 组件中有一个 img 标签,它的 src 属性绑定到 Vuex 状态.

I have an img tag in a Vue component with a binded src attribute to Vuex state.

<img :src="this.$store.state.imageDataURI">

我在 Vuex 中成功更新了该状态对象(见下文).

I am successfully updating that state object in Vuex (see below).

但是 img 标签没有被渲染(见下文).

However the img tag does not get rendered (see below).

我可以用 getter 解决这个问题,但只是好奇为什么这不起作用.我怀疑这与 Vue 的反应性模型有关.

I can fix this with getters but just curious as to why this doesn't work. I suspect this has to do with Vue's reactivity model.

有什么想法吗?

推荐答案

当附加到绑定时,this 不是必需的,如果我没记错的话可能会导致这样的问题.

When attaching to bindings, this isn't needed and if I'm remembering right can cause issues like this.

此外,您的商店结构看起来像您有一个模块 imageStore 这将命名 imageDataURI 元素.

Also your store structure looks like you have a module imageStore this would namepace of the imageDataURI element.

试试:

<img :src="$store.state.imageStore.imageDataURI">

这篇关于绑定img src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆