当前位置:网站首页>04 -- two ways of writing el and data
04 -- two ways of writing el and data
2022-07-25 03:06:00 【Live learning programming ideas】
el and data Two ways of writing
el The first way to write it
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>el And data Two ways of writing </title>
<!-- introduce vue -->
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- Prepare a container -->
<div id = "root">
<h1> Hello ,{
{
name}}</h1>
</div>
<script type="text/javascript">
Vue.config.productionTip = false // Set to false To prevent vue Generate production prompts at startup .
new Vue({
el: '#root',
data:{
name:' Silicon Valley '
}
})
</script>
</body>
</html>
el The second way to write
see Vue Instance object
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>el And data Two ways of writing </title>
<!-- introduce vue -->
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- Prepare a container -->
<div id = "root">
<h1> Hello ,{
{
name}}</h1>
</div>
<script type="text/javascript">
Vue.config.productionTip = false // Set to false To prevent vue Generate production prompts at startup .
const v = new Vue({
// el: '#root',
data:{
name:' Silicon Valley '
}
})
console.log(v)
</script>
</body>
</html>
page
Page output vue Instance object of 
Divided into $ The symbol of and No, $ The symbol of
const v = new Vue()
Output v yes vue Instance object Everything in the above red box is above itself , And what we need is vue Instance creation on the prototype object
v Is the instance Vue Is the creator of instances 
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>el And data Two ways of writing </title>
<!-- introduce vue -->
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- Prepare a container -->
<div id = "root">
<h1> Hello ,{
{
name}}</h1>
</div>
<script type="text/javascript">
Vue.config.productionTip = false // Set to false To prevent vue Generate production prompts at startup .
const v = new Vue({
// el: '#root',
data:{
name:' Silicon Valley '
}
})
console.log(v)
v.$mount('#root')
</script>
</body>
</html>
The second is more flexible , For example, add a timer , One second later , as follows :
<script type="text/javascript">
Vue.config.productionTip = false // Set to false To prevent vue Generate production prompts at startup .
const v = new Vue({
// el: '#root',
data:{
name:' Silicon Valley '
}
})
console.log(v)
setTimeout(() => {
v.$mount('#root')
}, 1000);
</script>
data The first way to write
// data The first way to write : Object type
data:{
name:' Silicon Valley '
}
data The second way to write
// data The second way to write : Functional expression
data:function() {
console.log("@@@", this) // Here this yes vue Instance object
return{
name:' Silicon Valley '
}
}
It can also be written as
data() {
console.log("@@@", this) // Here this yes vue Instance object
return{
name:' Silicon Valley '
}
}
above this Namely Vue Instance object 
summary
data And el Of 2 Species writing :
el Yes 2 Species writing
(1)new Vue When to configure el attribute
(2) First create Vue example , And then through vm.$mount(‘#root’) Appoint el Valuedata Yes 2 Species writing
(1) Object type
(2) Functional expression
How to choose : Either way of writing is OK at present , When you learn about components later ,data The functional expression must be used , Otherwise, an error will be reportedAn important principle :
from Vue Management functions , Never write arrow functions , Once you write the arrow function ,this It's not Vue The instance
边栏推荐
- FLASH read / write problem of stm32cubemx
- Hyperchain hyperblockchain Shi Xingguo was interviewed by 36 krypton: the amount of customer cooperation consulting is doubling
- Arduino + si5351 square wave generator
- JS foundation -- regular expression
- Nuscenes data set summary
- Wechat sports field reservation of the finished works of the applet graduation project (6) opening defense ppt
- Threat report in June: new bank malware malibot poses a threat to mobile banking users
- Handwriting promise
- Resolve the error: org.apache.ibatis.binding.bindingexception
- How to use blender to make 360 degree panorama and panoramic video?
猜你喜欢

Simulation Implementation of string function (Part 1)

How to take the mold for the picture of 1.54 inch TFT st7789 LCD screen

Read and upgrade st-link chip information and SWD burning media through STM32 stlink utility tool

Sequence diagram of UML diagram series

Learning Record V

Use reflection to convert RDD to dataframe

Define macros in makefile and pass them to source code

Decoding webp static pictures using libwebp

Learning record Xi
![[jailhouse article] certify the uncertified rewards assessment of virtualization for mixed criticality](/img/12/1763571a99e6ef15fb7f9512c54e9b.png)
[jailhouse article] certify the uncertified rewards assessment of virtualization for mixed criticality
随机推荐
[jailhouse article] certify the uncertified rewards assessment of virtualization for mixed criticality
mysql_ Record the executed SQL
The latest interview questions and analysis of software testing in 2022
Method of adding kernel in Jupiter notebook
Riotboard development board series notes (4) -- using Vpu hardware decoding
Vscode configuration, eslint+prettier combined with detailed configuration steps, standardized development
mysql_ User table_ Field meaning
ES6 - study notes
Arduino IDE for raspberry PI Pico development firmware localization installation tutorial
Query the information of students whose grades are above 80
JS foundation -- task queue and event loop
kettle_ Configure database connection_ report errors
Edit mathematical formulas in markdown
Color space (2) -- YUV
Several dpdk control frameworks
Riotboard development board series notes (6) -- buildreoot building system image
IO (1) -io layering
Tp5.0 background admin access
Tp5.1 paging (with parameter transfer)
Mark down learning