油猴脚本自动填写vue页面登录表单,点击登录按钮值被清空了

直接设置input的value是不行的,因为直接设置input.value没法触发input事件去更新vue里绑定的值,所以需要手动触发下input框的input事件

inputEl.value = 'xxx'

解决方案是:需要手动dispath input

let ev = new Event('input');
inputEl.dispatchEvent(ev)

示例:

(function() {
'use strict';
// Your code here...
window.onload = function(){
console.log('loaded')
const usernameEl = document.querySelector('#loginForm > div:nth-child(1) > div > div > input');
const passwordEl = document.querySelector('#loginForm > div:nth-child(2) > div > div > input');
let ev = new Event('input');
let ev2 = new Event('input');
setTimeout(()=>{
usernameEl && (usernameEl.value = 'admin') && usernameEl.dispatchEvent(ev)
setTimeout(()=>{
passwordEl && (passwordEl.value = 'test') && passwordEl.dispatchEvent(ev2)
},100)
}, 100)
}
})();
posted @   每天不emo  阅读(158)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示