简体   繁体   English

Vuejs,从 chrome 检查器控制台设置绑定到 model 的输入值

[英]Vuejs , set input value bound to a model from chrome inspector console

I have an VueJS app (compiled) and there is an input field and a submit button.我有一个 VueJS 应用程序(已编译),并且有一个输入字段和一个提交按钮。 The button checks if the input isnt empty.该按钮检查输入是否为空。 When i type the value in the input and press the button it works ok.当我在输入中键入值并按下按钮时,它可以正常工作。

Can I set the input value via javascript ( from chrome console )?我可以通过 javascript(来自 chrome 控制台)设置输入值吗?

I tried with我试过了

document.querySelectorAll('.form input')[0].dispatchEvent(new Event('focus'));
document.querySelectorAll('.form input')[0].value = 1
document.querySelectorAll('.form input')[0].dispatchEvent(new KeyboardEvent('keypress',{'key':'1'}));   

and then pressing the submit button but it says "field is empty".然后按下提交按钮,但它说“字段为空”。 Seems like doing that doesnt update the model.似乎这样做不会更新 model。

Any help?有什么帮助吗?

Thank you谢谢

If you have the devtools installed you can use $vm0 as the selected instance, if not select your HTML element that contains the app and use .__vue__如果您安装了 devtools,您可以使用 $vm0 作为所选实例,如果不是 select 您的 HTML 元素包含应用程序并使用.__vue__

To access the model of the instance, just use data.要访问实例的 model,只需使用数据即可。 So if your input is bound to a data variable called, search you just need to change that.因此,如果您的输入绑定到一个名为的数据变量,您只需更改它。

const vm = document.getElementById('web-page').__vue__
vm.$data.search = 'searching...'

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

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