Vue.js img src 连接变量和文本 [英] Vue.js img src concatenate variable and text
本文介绍了Vue.js img src 连接变量和文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将 Vue.js 变量与图像 URL 连接起来.
I want to concatenate Vue.js variable with image URL.
我的计算:
imgPreUrl : function() {
if (androidBuild) return "android_asset/www/";
else return "";
}
如果我为 android 构建:
If I build for android:
<img src="/android_asset/www/img/logo.png">
其他
<img src="img/logo.png">
如何将计算变量与 URL 连接起来?
How can I concatenate the computed variable with the URL?
我试过了:
<img src="{{imgPreUrl}}img/logo.png">
推荐答案
不能在属性中使用卷曲(小胡子标签).使用以下内容连接数据:
You can't use curlies (moustache tags) in attributes. Use the following to concat data:
<img v-bind:src="imgPreUrl + 'img/logo.png'">
或简短版本:
<img :src="imgPreUrl + 'img/logo.png'">
在 Vue 文档中阅读有关动态属性的更多信息.
Read more on dynamic attributes in the Vue docs.
这篇关于Vue.js img src 连接变量和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文