img src address in the inaccessible, the default image

Pictures taken from the address of the background, if the network address is incorrect or the picture is not good, not out of the picture page loads will affect the user experience, so it is necessary to show the path when you set about the image loading failure
<img style="width:15%;" :src="xxx" :onerror="defaultSrc">
export default {
  data(){
      return{
          defaultSrc:'this.src="' + require('../assets/img/defaultAvatar.png') + '"',
      }
  },
}

If direct written onerror='this.src="' + require('../assets/img/defaultAvatar.png') + '"', the page will be in srctwo addresses middle jump back and forth, resulting in a refresh cycle

Published 27 original articles · won praise 21 · views 4599

Guess you like

Origin blog.csdn.net/weixin_43997143/article/details/103970567