Vue学习笔记
基础信息
- 官网地址
https://cn.vuejs.org/ - 范例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23<!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>Document</title>
</head>
<body>
<div id="app">
<h2>{{message}}</h2> <!-- 赋值数据 -->
</div>
<script src="../js/vue.js"></script>
<script>
const app = new Vue({
el: '#app', //挂载需要进行管理的元素
data: {// 定义数据
message: 'Hello chibao'
}
})
</script>
</body>
</html> - mustache语法结构
{{ key }}
- v-once
仅更新一次数据1
<h2 v-once>{{message}}</h2>
- v-html
如果原数据是html格式的,可以直接解析后再进行展示1
<h2 v-html="url"></h2>
1
2
3
4
5
6
7
8
9const app = new Vue({
el: '#app', //挂载需要进行管理的元素
data: {// 定义数据
message: "hello",
url: "<a href='http://blog.colorccm.com'>blog</a>"
},
methods:{
}
}) - v-text
直接显示原数据1
<h2 v-text="message"></h2>
- v-pre
直接显示插值表达式,不进行解析1
<h2 v-pre>{{message}}</h2>
- v-cloak
斗篷,在还没有渲染的时候使用指定的样式遮盖1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30<!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>Document</title>
<style>
[v-cloak] {
display: none;
}
</style>
</head>
<body>
<div id="app" v-cloak>
<h2 >{{message}}</h2>
</div>
<script src="../js/vue.js"></script>
<script>
setTimeout(function(){
const app = new Vue({
el: '#app', //挂载需要进行管理的元素
data: {// 定义数据
message: "hello"
}
})
}, 1000)
</script>
</body>
</html> - v-bind
将数据绑定到dom的属性中1
2
3
4
5
6
7
8
9
10
11
12
13
14
15<div id="app">
<img v-bind:src="imgurl" alt="">
<img :src="imgurl" alt=""><!--简写-->
</div>
<script src="../js/vue.js"></script>
<script>
const app = new Vue({
el: '#app', //挂载需要进行管理的元素
data: {// 定义数据
imgurl: "https://cn.vuejs.org/images/logo.svg"
},
methods:{
}
})
</script> - v-for
循环列表中的内容再进行遍历展示1
<li v-for="item in movies">{{item}}</li>
1
2
3
4
5
6
7const app = new Vue({
el: '#app',
data: {
message: 'Hello',
movies: ['海王', '海贼王', '速度与激情']
}
}) - v-on
事件响应
Vue学习笔记
http://blog.colorccm.com/2021/07/20/it/vue/