手写实现简单的 hash 路由
let obj = {};
let inputDom = document.getElementById('input');
let spanDom = document.getElementById('span');
Object.defineProperty(obj, 'text', {
configurable: true,
enumerable: true,
get: function () {
console.log('获取数据');
},
set: function (value) {
console.log('更新数据', value);
inputDom.value = value;
spanDom.innerText = value;
},
});
inputDom.addEventListener('keyup', function (e) {
let value = e.target.value;
obj.text = value;
})
setTimeout(() => {
obj.text = 123;
},1000)