移动端一般图片长按会有保存的选项,所以只做pc端了
<template>
<div>
<img :src="pic" @click="fun" alt="">
</div>
</template>
<script>
import pic from '@/static/2.jpg'
export default {
data(){
return{
pic:pic
}
},
mounted(){
},
methods:{
fun(){
var a = document.createElement('a')
a.download = 'yh'
// 设置图片地址
a.href = this.pic;
a.click();
}
}
}
</script>
<style scoped>
</style>
网友评论