virtualvm2 观察者模式
2024-09-21 12:41:51
<template>
<div id="app">
<input type="text" v-model='msg'>
<div>
<p>{{msg}}</p>
</div>
</div>
</template>
<script>
class Observer{
static _observe(obj){
for(var key in obj){
//遍历obj对象
var value =obj[key];
if(typeof value ==='object'){
//如果值还是对象,则遍历处理
Observer._observe(value);
}
console.log("========def" ,key);
Object.defineProperty(obj, key, {
enumerable: true,
configurable: true,
set: function (newValue) {
if( value !== newValue ) {
var value = newValue;
console.log('setter:' + newValue);
}
},
get: function () {
console.log('getter:' +value);
return value;
}
});
}
}
}
class VM{
constructor(options){
this.$options = options;
this._obverse(this.$options.data);
return Object.assign({data:this.$options.data}, this.$options.methods );
}
_obverse(data) {
return Observer._observe(data);
}
}
var vm = new VM({
el: '#app',
data: {
msg:'hello'
},
methods: {
hello:function(){
console.log("hello");
}
}
})
vm.data.msg = "wwww"
var x = vm.data.msg;
vm.hello();
</script>
最新文章
- 在xampp中配置dvwa
- SqlServer字段说明查询
- IOS5中的Safari不兼容Javascript中的Date问题,做下笔录吧!奶奶的,折腾我半天!
- 转 如何理解 重要性采样(importance sampling)
- linux 问答
- require.js入门指南(二)
- NetMQ(ZeroMQ)Client =>; Server =>; Client 模式的实现
- NTP 服务器配置
- 关于IE打印预览内容显示不全的问题解决
- Windows Server 架设VPN要点
- 导入礼包时,遇到file_get_contents读取的文本,去除空格、换行等的方法
- Eclipse目录实解
- PDF转图片工具
- labview下载地址
- PHP实现微信商户支付企业付款到零钱功能代码实例
- Zookeeper Ephemeral结点使用心得
- linux 二级域名设置
- 分享一个shell脚本的坑:grep匹配+wc取值 在脚本执行后的结果与手动执行结果不一致
- Java循环中标签的作用(转)
- hook进程
热门文章
- windows server的应用软件限流QoS
- 全链路压测SOP
- 头条二面:宕机后,Redis如何实现快速恢复?
- vue super flow 多种形状
- vue element 可编辑表格行内验证
- elasticSearch(五)--排序
- Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on project
- pat乙级1012数字分类
- linux 服务器 重命名
- HOW TO RENDER TO A TEXTURE ARRAY IN UNITY