When img src path does not exist, the default image

<img :src=" zftx ? zftx : ' ' "  :onerror="defaultImg" />
 
 import defaultImage from '@/assets/baseInfo.png';
In the script by introducing import pictures, defaultImg variable is the default image,
 
In the data vue variable, the variable is defined defaultImg
defaultImg: `this.src =" $ {defaultImage} "`, // `` This is the meaning of the template,
 
When zftx is empty, src is empty at this time will perform: onerror = "defaultImg"

Note: As the project is vue of the front-end engineering, we need to introduce the picture, but can not directly use the image path, use the direct path of the picture will not be rendering.

If the article help you, help spot trouble a praise Oh! Hey! Technology bloggers do a fly!

Guess you like

Origin www.cnblogs.com/CatcherLJ/p/11206549.html