<img :src="src" alt="" v-show="countRatio!=null">
在data里面分别定义,根据页面数据展示的条件赋值src,引入图片的时候,在data里定义
up: require('../../../assets/images/uppunish.png'),
在函数里赋值就可以了
if (res.countRatio!=null) {
if (res.countRatio > 0) {
this.src = this.up;
this.countRatio = Math.round(res.countRatio * 100);
} else if (res.countRatio < 0) {
this.src = this.down;
this.countRatio = Math.round(res.countRatio * 100).toString().replace('-', '');
}
} else {
this.countRatio = null;
}
data定义数据部分

本文介绍如何在Vue中根据页面数据动态加载和显示图片,包括在data中定义图片路径,使用v-show控制图片显示,并根据不同的数据条件切换图片源。

1万+

被折叠的 条评论
为什么被折叠?



