‘use strict‘;
function view() {
let proxy = new Proxy({}, {
get(obj, propetry) {},
set(obj, propetry, value) {
console.log(obj)
console.log(propetry)
console.log(value)
document.querySelectorAll(`[v-model=‘${propetry}‘]`).forEach(item => {
item.value = value;
})
document.querySelectorAll(`[v-bind=‘${propetry}‘]`).forEach(item => {
item.innerHTML = value;
})
return true;
},
})
this.init = function() {
const els = document.querySelectorAll(‘[v-model]‘);
els.forEach(item => {
item.addEventListener(‘keyup‘, function() {
proxy[this.getAttribute(‘v-model‘)] = this.value;
})
})
}
}
new view().init();
原文:https://www.cnblogs.com/landuo629/p/14243915.html