当前位置:网站首页>[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.
边栏推荐
猜你喜欢

Chain Reading | The latest and most complete digital collection calendar-07.28

Operation table Function usage

view【】【】【】【】

Reflection 【Notes】

树结构——二叉查找树原理与实现

Timer (setInterval) on and off

十年磨一剑!数字藏品行情软件,链读APP正式开放内测!

最新最全的数字藏品发售日历-07.26

事务、存储引擎

Ten years of sharpening a sword!The digital collection market software, Link Reading APP is officially open for internal testing!
随机推荐
定时器(setInterval)的开启与关闭
链读好文:热加密存储与冷加密存储有什么区别?
Knowledge Distillation Thesis Learning
Content related to ZigBee network devices
网络安全7
.NET操作Excel高效低内存的开源框架 - MiniExcel
Reprint fstream, detailed usage of ifstream
链读 | 最新最全的数字藏品发售日历-07.28
笔记1
行盒子的盒模型
【笔记】集合框架体系 Collection
sqlplus 显示上一条命令及可用退格键
Common class BigDecimal
Consensus calculation and incentive mechanism
常用类 String概述
ORACLE system table space SYSTEM is full and cannot expand table space problem solving process
共识计算和激励机制
cesium add point, move point
你不知道的常规流
Linux数据库Oracle客户端安装,用于shell脚本用sqlplus连接数据库