<!DOCTYPE html
>
<html lang
="en">
<head
>
<meta charset
="UTF-8">
<title
>Title
</title
>
</head
>
<body
>
<script
>
var data
= {
msg
: 'hello vue'
}
var vm
= {}
for(let key
in data
) {
let val
= data
[key
]
Object
.defineProperty(vm
, key
, {
get:function () {
return val
},
set:function (newVal
) {
val
= newVal
data
[key
] = newVal
}
})
}
</script
>
</body
>
</html
>
以上代码就是可以通过vm访问data里面的数据,把data里面的数据劫持住,然后对data进行操作
转载请注明原文地址:https://ipadbbs.8miu.com/read-1770.html