Vue项目声明式渲染
<!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">
{{ message }}
</div>
//导入vue 依赖cdn
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
})
</script>
</body>
</html>
Vue条件渲染 “v-if”
<body>
<div v-if="type === 'A'">A</div>
<div v-else-if="type === 'B'">B</div>
<div v-else-if="type === 'C'">C</div>
<div v-else>Not A/B/C</div>
//导入vue 依赖cdn
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
type: 'A'
}
})
</script>
</body>
Vue列表渲染 v-for
<body>
<div id="app">
<li v-for="item in items">
{{item.message}}
</li>
//还支持一个可选的第二个参数,即当前项的索引。
<li v-for="(item,index) in items">
{{item.message}}--{{index}}
</li>
</div>
//导入vue 依赖cdn
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
items: [
{message: '账号'},
{message: '密码'},
{message: '头像'},
{message: '简介'}
]
}
})
</script>
</body>