Vue not binding data to image src

自作多情 提交于 2020-07-30 07:53:29

问题


I'm having a problem binding data to src attribute in image. This is my code where I have :src and trying to bind image to it. Also I printed this.image in created() and it is getting printed fine. Here is the code

<img class="d-block w-100" :src="image" />

    export default {
      name: 'How',
      data(){
        return{
          image: '../../assets/img/how_to_oka_6.png'
        }
      }
    }

回答1:


You should import that image since it considered as a module like :

<img class="d-block w-100" :src="image" />

    export default {
      name: 'How',
      data(){
        return{
          image: require('../../assets/img/how_to_oka_6.png')
        }
      }
    }


来源:https://stackoverflow.com/questions/55579284/vue-not-binding-data-to-image-src

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!