简体   繁体   English

如何使用 Vuejs 在 Safari 中的表单上侦听粘贴事件

[英]How to listen for a paste event on a form in Safari with Vuejs

I have a form in Vuejs.我在 Vuejs 中有一个表单。 On the input for a credit card number, I have this: @change="updateNumber($event)"在输入信用卡号时,我有这个: @change="updateNumber($event)"

In Chrome, when I paste a credit card number, or one is autofilled from my saved cards, this is recognized as a "change".在 Chrome 中,当我粘贴信用卡号,或者从我保存的卡中自动填充一个信用卡号时,这被识别为“更改”。 However, that isn't the case in Safari.但是,Safari 中的情况并非如此。 A change event isn't emitted.不会发出更改事件。 I'm wondering which event I need to listen for and how to set that custom event listener in my Vuejs component.我想知道我需要监听哪个事件以及如何在我的 Vuejs 组件中设置自定义事件监听器。 Thank you!谢谢!

Instead of listening for @change listen for @input which will trigger an event when a user pastes into the input.而不是监听@change ,而是监听@input ,当用户粘贴到输入时会触发一个事件。

Your final code becomes:您的最终代码变为:

@input="updateNumber($event)"

Here is a working fiddle that I tested in both Chrome and Safari这是我在 Chrome 和 Safari 中测试的工作小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM