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

查看:45
本文介绍了输入的 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 通过其他脚本动态更改值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆