欢迎来到"雪碧聊技术"CSDN博客!
在这里,您将踏入一个专注于Java开发技术的知识殿堂。无论您是Java编程的初学者,还是具有一定经验的开发者,相信我的博客都能为您提供宝贵的学习资源和实用技巧。作为您的技术向导,我将不断探索Java的深邃世界,分享最新的技术动态、实战经验以及项目心得。
让我们一同在Java的广阔天地中遨游,携手提升技术能力,共创美好未来!感谢您的关注与支持,期待在"雪碧聊技术"与您共同成长!
目录
①等我们学到以后,必须使用这种用函数返回data的方式。(如果不这么做,以后肯定会报错)
[②用函数返回data时,一定不要写箭头函数()=>{},因为这么写,导致this不再是vue实例,而是window ,根本原因是箭头函数中不存在this的概念,因此就会往上找this。](#②用函数返回data时,一定不要写箭头函数()=>{},因为这么写,导致this不再是vue实例,而是window ,根本原因是箭头函数中不存在this的概念,因此就会往上找this。)
①M:模型(Model),对应vue实例的data中的数据。
③VM:视图模型(ViewModel),指的是vue实例对象。
注意:由于vue实例在MVVM模型中,是VM这个角色,因此以后vue实例都会命名为VM这个名称。
[举例:在容器中,通过{{ }}可以访问vue实例的所有内容。](#举例:在容器中,通过{{ }}可以访问vue实例的所有内容。)
1、Object.defineProperty方法是用来干什么的?
①通过Object.defineProperty添加的属性,默认是不可以遍历的
②通过Object.defineProperty添加的属性,默认是不可以修改的
③通过Object.defineProperty添加的属性,默认是不可以删除的
6、Object.defineProperty中的get方法
②举例:通过读取变量number的值,作为追加属性age的值。
7、Object.defineProperty中的set方法
一、el、data的两种写法
1、el的作用
用来将容器和vue实例进行绑定。
举例:

2、el的替代写法
vue实例名.$mount('容器选择器')
举例:

3、data的作用
声明vue实例中的数据,这样才能给html容器(在vue中叫"模板")中的数据赋值。
4、data的替代写法
举例:

进一步化简:

注意:
①等我们学到以后,必须使用这种用函数返回data的方式。(如果不这么做,以后肯定会报错)
②用函数返回data时,一定不要写箭头函数()=>{},因为这么写,导致this不再是vue实例,而是window ,根本原因是箭头函数中不存在this的概念,因此就会往上找this。
5、总结

二、理解MVVM
1、什么是MVVM?
①M:模型(Model),对应vue实例的data中的数据。
②V:视图(View),模板,即html容器。
③VM:视图模型(ViewModel),指的是vue实例对象。

2、图示

运行结果:

注意:由于vue实例在MVVM模型中,是VM这个角色,因此以后vue实例都会命名为VM这个名称。
举例:

3、总结

举例:在容器中,通过{{ }}可以访问vue实例的所有内容。

三、Object.defineProperty方法
1、Object.defineProperty方法是用来干什么的?
用来给对象添加一个属性。
2、举例:给对象添加一个属性

运行结果:

3、存在的问题
①通过Object.defineProperty添加的属性,默认是不可以遍历的
举例:

运行结果:

②通过Object.defineProperty添加的属性,默认是不可以修改的
举例:

③通过Object.defineProperty添加的属性,默认是不可以删除的
举例:

4、解决上述问题

5、Object.defineProperty方法的好处
使用该方法添加的对象属性,可以对其进行很多限制,比如:对象的属性是否可以被枚举、被修改、被删除等等,在某些特定场景下,是需要这些限制的。
6、Object.defineProperty中的get方法
①作用:读取变量的值,作为属性的值。
②举例:通过读取变量number的值,作为追加属性age的值。

运行效果:


7、Object.defineProperty中的set方法
①作用:用来接收属性被修改时,修改后的值。
②举例:


③存在的问题:person中的age属性没变化

④改进:在set方法中,刷新number变量的值

运行效果:

8、方法简写问题
举例:

简写后:

四、数据代理
1、什么是数据代理?
通过一个对象代理,对另一个对象中的属性进行操作(读/写)。
2、举例:让对象obj2,代理对象obj

运行结果:
