The default picture set by img does not display

some pictures are not available, set the default picture, but the default picture is not displayed, there is only one placeholder.

it is not possible to change the picture, nor to write the default picture address directly, nor to write the picture address as an absolute path

related codes

< li VFF = "(item,index) in listData": key= "index" VMI if = "listData.length > 0" >

<a :href="item.url" target="_blank">
    <img :src="item.file.url" alt="" width="80px" height="80px" :onerror="defaultImg" />
    <div>{{item.title}}</div>
</a>

data () {

return{
    defaultImg:"this.src="" + require("../../../assets/img/fuwu.jpg") +"";this.onerror=null"
}

}

url

this is the default picture you want to display

Mar.17,2022

1. Your goal is to have no picture to show the default picture?

import defaultUrl from 'xxxx';
   <img :src="item.file.url?item.file.url:defaultUrl" alt="" width="80px" height="80px"/>

2. Your goal is to display the default picture only when the image fails to load?

import defaultUrl from 'xxxx';
<img :src="item.file.url" alt="" width="80px" height="80px" @error="loadErrorFun(item.index)" /> //:indexv-for
loadErrorFun(index){
    this.listData[index].item.file.url = defaultUrl;
    this.$forceUpdate();
}


data () {

return {
    defaultImg: 'this.src="' + require("../../../assets/img/fuwu.jpg") +'"'
}

}


Can the picture entered by

require be stitched directly with the string? It feels like there's something wrong with the path in this place.

I use the following methods, which is no problem.

put the picture in the static folder static, and then defaultImg assigns a string directly, like this:
defaultImg: 'this.src= ". / static/img/fuwu.jpg"; this.onerror=null'

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35f08-2b827.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35f08-2b827.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?