-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[vue] 怎么解决vue动态设置img的src不生效的问题? #553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
这里还可以产生一个问题,为什么Vue中给img标签设置src属性会不生效 |
因为动态添加src被当做静态资源处理了,没有进行编译,所以要加上require。 |
不是应该 require('@/assets/images/xxx.png') 这样吗??你这样多浪费资源啊 @chenqim |
require('@/assets/images/xxx.png') |
学到了 |
这个 |
这个应该和vue没关系把,图片,需要改变的时候,就切换src啊 |
@chenqim 实际中并不需要这样,直接在src里面写@/assets/xxx.png即可(前提是你的项目通过vue-cli生成或配置了file-loader) |
用require()引入 |
为什么不把自己的思路说出来呢?不应该是提出问题,解决问题吗? |
因为动态添加src被当做静态资源处理了,没有进行编译,所以要加上require。 |
这个问题应该是指 vue 这种情况吧
用 this.$set |
[vue] 怎么解决vue动态设置img的src不生效的问题?
The text was updated successfully, but these errors were encountered: