绑定img src

编程入门 行业动态 更新时间:2024-10-12 01:23:21
本文介绍了绑定img src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在一个 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 23:30:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1144904.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   img   src

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!