输入上的 v-model 通过其他脚本动态更改值? [英] v-model on input that dynamically changes value by other script ?

查看:64
本文介绍了输入上的 v-model 通过其他脚本动态更改值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个输入用于存储来自谷歌地图脚本的 lat 和 lng,如果用户更改标记的位置 => 这两个输入获取用户啄的 lat 和 lng,所以我想获取这两个输入的值,我尝试了 v-model 但它没有用我实际上注意到只有当我通过键入或粘贴某些内容来更改这些输入的值时才会触发 v-model.有什么方法可以让我的 Vue 实例获得这些输入的值(比如 on-change)?

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'))

在你的元素上.这适用于