v-model on input that dynamically changes value by other script ?(输入的 v-model 通过其他脚本动态更改值?)
问题描述
我有两个输入存储来自谷歌地图脚本的 lat 和 lng,如果用户更改标记的位置 => 这两个输入得到用户啄的 lat 和 lng,所以我想得到这两个输入的值,我尝试了 v-model 但它不起作用我实际上注意到只有当我通过键入或粘贴某些内容来更改这些输入的值时才会触发 v-model.有没有一种方法可以将这些输入的值(如 on-change)传递给我的 Vue 实例?
I have two input that store lat and lng from google map script, if the user changes the marker's position => these two inputs get the lat and lng that the user pecked, so I wanna get the value of these two inputs, I tried v-model but it didnt work I actually noticed that the v-model will be fired only if I changed the value of these input by typing or pasting something in. Is there a way that I can get the value of these inputs (like on-change) to my Vue instance?
推荐答案
要在输入值从外部脚本动态更改后触发 Vue.js 读取输入值,您必须调用:
To trigger Vue.js to read your input's value after it changes dynamically from an external script, you have to call:
document.querySelector('#element-id').dispatchEvent(new Event('input'))
在您的元素上.这适用于 <input>
和 <textarea>
元素.对于 <select>
元素,您必须调用:
on your element. This works on both <input>
and <textarea>
elements. For <select>
elements you would have to call:
document.querySelector('#element-id').dispatchEvent(new Event('change'))
这篇关于输入的 v-model 通过其他脚本动态更改值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:输入的 v-model 通过其他脚本动态更改值?


- 从原点悬停时触发 translateY() 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01