当前位置:网站首页>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
边栏推荐
- Function of each layer of data warehouse
- PHP record
- Pypi counts the number of Downloads
- JS foundation -- object static method
- 6.0 cancellation of member registration verification code
- Reasons for not sending requests after uni app packaging
- Recursive and non recursive methods are used to realize the first order, middle order and second order traversal of binary tree respectively
- Color space (2) -- YUV
- Go multiplexing
- Flink's study notes
猜你喜欢

Mark down learning

Arduino IDE for raspberry PI Pico development firmware localization installation tutorial

Use unicloud cloud function to decode wechat motion steps in applet

Banana pie bpi-m5 toss record (3) -- compile BSP

The latest interview questions and analysis of software testing in 2022

Preliminary foundation JVM

JS foundation -- data

Dynamic programming -- Digital DP

What should I do when the interface encounters jsonstring

Conceptual distinction between Po, Bo, VO, dto and POJO
随机推荐
Edit mathematical formulas in markdown
Riotboard development board series notes (V) -- porting u-boot
JS foundation -- hijacking of this keyword
Solve ''_ Xsrf 'argument missing from post
Riotboard development board series notes (VII) -- the use of framebuffer
Decoding webp static pictures using libwebp
Wechat sports field reservation of the finished works of the applet graduation project (6) opening defense ppt
Details of happens before rules
Threat report in June: new bank malware malibot poses a threat to mobile banking users
Application method and practical case of sqlmap of penetration test SQL injection
Time formatting
How to switch terminators in PostgreSQL?
Simulation Implementation of string function (Part 1)
JS written test question -- promise, setTimeout, task queue comprehensive question
Experiment 4 CTF practice
Go common standard library -time
Beginners must see the markdown User Guide
Use of stm32cubemonitor Part II - historical data storage and network access
Keil compile download error: no algorithm found for: 08000000h - 08001233h solution
Domestic edge computing organization and product research