点击图片,触发上传文件的效果,上效果图
思路:
使用input标签,设置type=”file“,将input样式透明度设置为0,背景设置为图片即可。
上代码
<div class="imageFileInput">
<input
class="fileInput"
type="file"
@change="onFileChanged"
/>
</div>
<div class="shuJuName">数据上传</div>
<style lang="less" scoped>
.imageFileInput {
width: 40px;
height: 40px;
background: url(../../../src/assets/imgs/shangchuan.png);
background-size: cover;//设置图片根据盒子大小自适应展示
}
.shuJuName {
font-size: 12px;
font-weight: 400;
color: #666666;
margin-top: 4px;
}
.fileInput {
height: 100%;
width: 40px;
opacity: 0;//设置透明度为0
}
</style>