Skip to main content

简单实现 MVVM

const data = {};
const input = document.getElementById("input");

Object.defineProperty(data, "text", {
set(value) {
input.value = value;
this.value = value;
},
});

input.onchange = function (e) {
data.text = e.target.value();
};
var instance = null;

class Storage {
static getInstance() {
if (!instance) {
instance = new Storage();
}
return instance;
}
setItem = (key, value) => localStorage.setItem(key, value),
getItem = key = > localStorage.getItem(key)
}