vue3 给dom添加方法
要求为了实现点击上传图片,因为input设置了display:none
<div class="cursor-pointer border border-grays-700 overflow-hidden" style="width: 11.25rem; height: 7.5rem;"
@click="upload">
<!-- <img src="../../../assets/upload.png" alt="" class="w-full h-full"> -->
<input type="file" accept="image/*" class="inputUpload cursor-pointer"
style="font-size: 0; padding: 0; cursor: pointer; display: none;" id="cover" ref="uploadcover"
@change="uploadcoverChange">
</div>
const uploadcover = ref(null)
const upload = () => {
uploadcover.value.click()
}
const uploadcoverChange = (file) => {
console.log(uploadcover.value.files[0]);
}
vue2中是通过
vue3中通过定义 xx = ref(null)
在通过xx.value实现获取dom