Vue中动态绑定img的src属性(v-bind)

今天遇到一个特别坑爹问题,页面中使用img动态绑定图片路径时总是不显示。(处理前的代码)

{{item.name}}
Merchant:[
    {imgUrl:'../../assets/image/凯叔讲故事.png',name:'凯叔讲故事'},
    {imgUrl:'../../assets/image/樊登读书.png',name:'樊登读书'},
    {imgUrl:'../../assets/image/QQ音乐.png',name:'QQ音乐'},
    {imgUrl:'../../assets/image/滴滴出行.png',name:'滴滴出行 '},
    {imgUrl:'../../assets/image/沃尔玛.png',name:'沃尔玛'},
    {imgUrl:'../../assets/image/星巴克.png',name:'星巴克'},
    {imgUrl:'../../assets/image/爱奇艺.png',name:'爱奇艺'},
    {imgUrl:'../../assets/image/腾讯视频.png',name:'腾讯视频'},
    {imgUrl:'../../assets/image/优酷.png',name:'优酷'},
    {imgUrl:'../../assets/image/携程.png',name:'携程'},
  ],

Vue中动态绑定img的src属性(v-bind)_第1张图片

 

 

解决办法:图片链接是需要通过 require包裹。这样图片就可以正常显示啦。(网络请求的数据应该做相应的处理) 

*** 图片的路径不要出行中文,这里只是做演示

Merchant:[
  {imgUrl:require('../../assets/image/凯叔讲故事.png'),name:'凯叔讲故事'},
  {imgUrl:require("../../assets/image/樊登读书.png"),name:'樊登读书'},
  {imgUrl:require("../../assets/image/QQ音乐.png"),name:'QQ音乐'},
  {imgUrl:require("../../assets/image/携程.png"),name:'携程'},
  {imgUrl:require("../../assets/image/滴滴出行.png"),name:'滴滴出行'},
  {imgUrl:require("../../assets/image/沃尔玛.png"),name:'沃尔玛'},
  {imgUrl:require("../../assets/image/星巴克.png"),name:'星巴克'},
  {imgUrl:require("../../assets/image/爱奇艺.png"),name:'爱奇艺'},
  {imgUrl:require("../../assets/image/腾讯视频.png"),name:'腾讯视频'},
  {imgUrl:require("../../assets/image/优酷.png"),name:'优酷'},
],

Vue中动态绑定img的src属性(v-bind)_第2张图片

你可能感兴趣的:(Vue中v-bind爬坑笔记,vue,vue.js,前端,javascript)