Vue中动态设置img的src值
Vue中动态设置img的src值问题循环li组件时,动态设置img设置img时,src属性报错src数据格式 "companyImages":["http://localhost:8080/cszj/image/image?image=2757dcrz7e0v5stxwqsvd4dk4ezdvvqo","http://localhost:8080/
·
Vue中动态设置img的src值
问题
- 循环li组件时,动态设置img
- 设置img时,src属性报错
src数据格式
"companyImages":[
"http://localhost:8080/cszj/image/image?image=2757dcrz7e0v5stxwqsvd4dk4ezdvvqo",
"http://localhost:8080/cszj/image/image?image=3757dcrz7e0v5stxwqsvd4dk4ezdvvqo"
]
错误的做法
<li v-for="(item,idx) in company_images">
<img id="company_image" src="{{item}}"/>
<el-button>删除</el-button>
</li>
<li v-for="(item,idx) in company_images">
<img id="company_image" src="{{item.toString()}}"/>
<el-button>删除</el-button>
</li>
<li v-for="(item,idx) in company_images">
<img id="company_image" :src="{{item.toString()}}"/>
<el-button>删除</el-button>
</li>
<li v-for="(item,idx) in company_images">
<img id="company_image" src="{{company_images[idx]}"/>
<el-button>删除</el-button>
</li>
<li v-for="(item,idx) in company_images">
<img id="company_image" :src="{{company_images[idx]}"/>
<el-button>删除</el-button>
</li>
等等用了{{}}表达式的
正确的做法【:相当于bind:】
<li v-for="(item,idx) in company_images">
<img id="company_image" :src="item"/>
<el-button>删除</el-button>
</li>
其实在编译环境下通过颜色是有区别的
更多推荐
已为社区贡献16条内容
所有评论(0)