随便搞个div,里面放个input并设置display:none;点击这个div,触发点击input的事件。之后对着div搞样式就ok了.
<div id="div" @click="newPhoto() >
<input id="input" type="file" ref="photo" @change="uploadPhoto($event)" />
</div>
<style>
div{
width: 120px;
height: 120px;
background: #000;
}
input{
display: none;
}
</style>
js代码
$(document).ready(function(){
$('#div').click(function(){
$('#input').click();
});
});
vue代码
newPhoto(){
console.log('点击了头像');
this.$refs.photo.click();
},
uploadPhoto(e){
console.log('上传头像咯',e);
}