vue2
监听data变化的核心API–Object.defineProperty
- 基本使用
<input type="text" id="in" placeholder="请输入姓名..."/>输入的姓名为:<span id="out"></span> <br>
<input type="text" id="in1" placeholder="请输入年龄..."/> 输入的年龄为:<span id="out1"></span>
let int = document.getElementById('in');
let out=document.getElementById('out');
const data={
name:'peak',age:10}
Object.keys(data).forEach((key)=>{
Object.defineProperty(data,key,{
enumerable:true,
configurable:true,
get:()=>{
console.log(`get`)
return data.key;
}