当前位置:网站首页>MVVM模型
MVVM模型
2022-04-23 18:35:00 【_洋】
含义
- M: 模型(Model) :对应data中的数据
- V: 视图(View):模板,对应的是页面
- VM: 视图模型(ViewModel) : Vue实例对象
ViewModel简称vm,又对应着vue,所以vue创建的对象经常使用使用变量名vm接收。
eg:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<script src="../js/vue.js"></script>
</head>
<body>
<div id="root">
<h1>学校名称:{
{name}}</h1>
<h1>学校地址:{
{address}}</h1>
</div>
</body>
<script> Vue.config.productionTip = false; new Vue({
el:'#root', data:{
name:'百度', address:'北京' } }) </script>
</html>
分析:
特点
1.data中所有的属性,最后都出现在了vm身上。——数据代理
eg:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<script src="../js/vue.js"></script>
</head>
<body>
<div id="root">
<h1>学校名称:{
{name}}</h1>
<h1>学校地址:{
{address}}</h1>
</div>
</body>
<script> Vue.config.productionTip = false; const vm = new Vue({
el:'#root', data:{
name:'百度', address:'北京' } }) console.log(vm); </script>
</html>
2.vm身上所有的属性及 Vue原型上所有属性,在Vue模板中都可以直接使用。
eg:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<script src="../js/vue.js"></script>
</head>
<body>
<div id="root">
<h1>学校名称:{
{name}}</h1>
<h1>学校地址:{
{address}}</h1>
<h1>监听:{
{$listeners}}</h1>
<h1>_hasHookEvent:{
{_hasHookEvent}}</h1>
</div>
</body>
<script> Vue.config.productionTip = false; const vm = new Vue({
el:'#root', data:{
name:'百度', address:'北京' } }) console.log(vm); </script>
</html>
输出:
版权声明
本文为[_洋]所创,转载请带上原文链接,感谢
https://blog.csdn.net/mantou_riji/article/details/124366023
边栏推荐
- listener.log
- powerdesigner各种字体设置;preview字体设置;sql字体设置
- JD freefuck Jingdong HaoMao control panel background Command Execution Vulnerability
- 【ACM】509. 斐波那契数(dp五部曲)
- Daily CISSP certification common mistakes (April 15, 2022)
- STM32 learning record 0008 - GPIO things 1
- ctfshow-web361(SSTI)
- WIN1 remote "this may be due to credssp encryption Oracle correction" solution
- Mysqldump backup database
- QT reading and writing XML files (including source code + comments)
猜你喜欢
Kettle paoding jieniu Chapter 17 text file output
Function recursion and solving interesting problems
Introduction to quantexa CDI syneo platform
解决:cnpm : 无法加载文件 ...\cnpm.ps1,因为在此系统上禁止运行脚本
Use stm32cube MX / stm32cube ide to generate FatFs code and operate SPI flash
Analysez l'objet promise avec le noyau dur (Connaissez - vous les sept API communes obligatoires et les sept questions clés?)
Use Chenxi bookkeeping book to analyze the balance of revenue and expenditure of each account in a certain period of time
listener.log
多功能工具箱微信小程序源码
In win10 system, all programs run as administrator by default
随机推荐
ctfshow-web362(SSTI)
14 py games source code share the second bullet
教你用简单几个步骤快速重命名文件夹名
iptables初探
Halo 开源项目学习(七):缓存机制
实战业务优化方案总结---主目录---持续更新
QT excel operation summary
Creation and use of QT dynamic link library
Serial port debugging tools cutecom and minicom
Machine learning theory (7): kernel function kernels -- a way to help SVM realize nonlinear decision boundary
listener.log
Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
Daily CISSP certification common mistakes (April 12, 2022)
MATLAB小技巧(6)七种滤波方法比较
listener. log
CISSP certified daily knowledge points (April 12, 2022)
Vulnérabilité d'exécution de la commande de fond du panneau de commande JD - freefuck
How to ensure the security of futures accounts online?
Ctfshow - web362 (ssti)
Resolves the interface method that allows annotation requests to be written in postman