当前位置:网站首页>[Difference between el and template]
[Difference between el and template]
2022-08-10 05:51:00 【A thousand piles of snow and a long street】
main.js
import Vue from 'vue'new Vue({el: ' #app',data: {name:'chen'}})
index.html
<div id="app">{{message}}</div>
After normal operation, let's consider a problem:
- If we want to display the data in data in the interface, we must modify index.html
- If we customize the component later, we must also modify index.html to use the component
- But in the future development of the html template, I don't want to manually modify it frequently. Is it possible to do it?
Define the template property:
- In the previous Vue instance, we defined the el attribute to bind with #app in index.html, so that the Vue instance can manage its content later
- Here, we can put the { in the div element{message}}The content is deleted, and only one element with the basic id of div is retained
- But if I still want to show {{message}}, what should I do?
We can define another template attribute, the code is as follows:
new Vue({el: '#app',template: '{{message}}',data: {message: 'Hello!'}})
Repackage and run the program, showing the same result and HTML code structure
So, what is the relationship between el and template template?
- In our previous study, we know that el is used to specify the DOM to be managed by Vue, which can help to parse the instructions, event monitoring and so on.
- If the template is also specified in the Vue instance, the content of the template template will replace the mounted template of the corresponding el.
What's the benefit of doing this?
- After doing this, we don't need to operate index.html again in future development, just write the corresponding tags in the template
However, writing template modules is very troublesome.
- It doesn't matter, the content in the template template will be extracted later.It will be written in three parts: template, script, style, and the structure becomes very clear.
边栏推荐
- 网络安全3
- ORACLE system table space SYSTEM is full and cannot expand table space problem solving process
- I use this recruit let the team to improve the development efficiency of 100%!
- 力扣——省份数量
- shell脚本中利用sqlplus操作数据库
- redis集群模式
- 数据库 笔记 创建数据库、表 备份
- 并查集原理与API设计
- Small program wx.request simple Promise package
- 私有化搭建个人网盘 NextCloud
猜你喜欢
最新最全的数字藏品发售日历-07.26
链读|最新最全的数字藏品发售日历-07.29
栈和队列
.las转.txt 再转.pcd,编译运行中出现的错误
tinymce rich text editor
ORACLE系统表空间SYSTEM占满无法扩充表空间问题解决过程
Day1 微信小程序-小程序代码的构成
The latest and most complete digital collection sales calendar-07.27
定时器(setInterval)的开启与关闭
I use this recruit let the team to improve the development efficiency of 100%!
随机推荐
cesium 监听地图缩放或放大来控制地图上添加的内容是否展示
redis集群模式
transaction, storage engine
Batch add watermark to pictures batch scale pictures to specified size
Chain Reading|The latest and most complete digital collection sales calendar-08.02
Bifrost 同步数据库实现微服务跨库数据同步
第五次实验
力扣——统计只差一个字符的子串数目
ORACLE系统表空间SYSTEM占满无法扩充表空间问题解决过程
Collection tool class
第十天作业
Small program wx.request simple Promise package
2021-07-09
Index Notes【】【】
共识计算和激励机制
tinymce rich text editor
Set Sources Resources and other folders in the IDEA project
符号表
Common class BigDecimal
学生管理系统以及其简单功能的实现