1,html
<img :src="imgUrl" alt="二维码图片"> <span @click="downloadImg()"></span>
2,data中
// 引入图片 import codeIMG from '@/assets/code.jpg'; data(){ return { imgUrl: require("../../assets/img/upload.png") } }
3,方法
methods: { downloadImg(){ var a = document.createElement('a') a.download = name || 'pic' // 设置图片地址 a.href = this.imgUrl; a.click(); }, }