当前位置:网站首页>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
边栏推荐
- The vivado project corresponding to the board is generated by TCL script
- From introduction to mastery of MATLAB (2)
- WIN1 remote "this may be due to credssp encryption Oracle correction" solution
- Test questions of daily safety network (February 2024)
- Use Chenxi bookkeeping book to analyze the balance of revenue and expenditure of each account in a certain period of time
- Jeecg boot microservice architecture
- Analysez l'objet promise avec le noyau dur (Connaissez - vous les sept API communes obligatoires et les sept questions clés?)
- Robocode Tutorial 4 - robocode's game physics
- Mysqldump backup database
- 【ACM】455. Distribute Biscuits (1. Give priority to big biscuits to big appetite; 2. Traverse two arrays with only one for loop (use subscript index -- to traverse another array))
猜你喜欢
Introduction to quantexa CDI syneo platform
Use Chenxi bookkeeping book to analyze the balance of revenue and expenditure of each account in a certain period of time
机器学习理论之(8):模型集成 Ensemble Learning
From introduction to mastery of MATLAB (2)
多功能工具箱微信小程序源码
Solution to Chinese garbled code after reg file is imported into the registry
Notepad + + replaces tabs with spaces
Deep learning classic network analysis and target detection (I): r-cnn
Robocode Tutorial 4 - robocode's game physics
使用晨曦记账本,分析某个时间段每个账户收支结余
随机推荐
Daily network security certification test questions (April 13, 2022)
回路-通路
Daily network security certification test questions (April 15, 2022)
Quantexa CDI(场景决策智能)Syneo平台介绍
Quantexa CDI(场景决策智能)Syneo平台介绍
Can filter
STM32: LCD display
ESP32 LVGL8. 1 - label (style 14)
Deep learning classic network analysis and target detection (I): r-cnn
Spark performance optimization guide
Daily CISSP certification common mistakes (April 13, 2022)
串口调试工具cutecom和minicom
机器学习理论之(8):模型集成 Ensemble Learning
机器学习理论之(7):核函数 Kernels —— 一种帮助 SVM 实现非线性化决策边界的方式
QT tablewidget insert qcombobox drop-down box
Daily CISSP certification common mistakes (April 11, 2022)
QT notes on qmap container freeing memory
Database computer experiment 4 (data integrity and stored procedure)
SQL database syntax learning notes
Introduction to quantexa CDI syneo platform