[英]How to force @change/@input event to fire whenever user inputs data?
I can use input DOM element
to upload an image and pass its data to a function like so:我可以使用
input DOM element
上传图像并将其数据传递给 function,如下所示:
<input type="file" @change="myFunction"/>
but since the event is @change
, it only fires when the image data changes.但由于事件是
@change
,它仅在图像数据更改时触发。 When I want to upload the same image twice, the event doesn't fire.当我想两次上传同一张图片时,该事件不会触发。 I've tried using the
@input
event instead but it behaves exactly the same, not firing when the same image is uploaded.我尝试使用
@input
事件,但它的行为完全相同,在上传相同的图像时不会触发。
Is there any way to upload the same image twice?有没有办法两次上传同一张图片?
You can achieve that by attaching the @click
event and then empty the target value event.currentTarget.value = ''
您可以通过附加
@click
事件然后清空目标值event.currentTarget.value = ''
实现
Live Demo :现场演示:
new Vue({ el: '#app', methods: { myClickFunction(e) { e.currentTarget.value = ''; }, myFunction() { console.log('call'); } } })
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="app"> <input type="file" @click="myClickFunction" @change="myFunction"/> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.