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

树结构——2-3树图解

链表API设计

ORACLE system table space SYSTEM is full and cannot expand table space problem solving process

图片批量添加水印批量加背景缩放批量合并工具picUnionV4.0

MySql 约束

链读|最新最全的数字藏品发售日历-08.02

One step ahead, don't miss it again, the chain reading APP will be launched soon!

棋类游戏-五子棋小游戏

Operation table Function usage

定时器(setInterval)的开启与关闭
随机推荐
ZigBee 网络设备相关内容
最新最全的数字藏品发售日历-07.27
sqlplus displays the previous command and the available backspace key
链表API设计
impdp import data
I use this recruit let the team to improve the development efficiency of 100%!
impdp 导入数据
Smart contracts and DAPP decentralized applications
集合 Map
学生管理系统以及其简单功能的实现
十年磨一剑!数字藏品行情软件,链读APP正式开放内测!
力扣——统计只差一个字符的子串数目
Canal reports Could not find first log file name in binary log index file
wiki confluence installation
Batch add watermark to pictures batch scale pictures to specified size
opencv
IDEA的database使用教程(使用mysql数据库)
2021-06-22
Ten years of sharpening a sword!The digital collection market software, Link Reading APP is officially open for internal testing!
Content related to ZigBee network devices