Template grammar - inserting text
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
<h1 v-text="texts">你好,世界</h1>
<h1 v-text="htmls"></h1>
</div>
<script src="./vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
texts: 'Hello World',
htmls: '<a href="">Hello World</a>'
}
});
</script>
</body>
</html>
Template syntax - insert labels
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
<h1 v-html="htmls"><a href="">{{texts}}</a></h1>
</div>
<script src="./vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
texts: '你好,世界',
htmls: '<a href="">Hello World</a>'
}
});
</script>
</body>
</html>
Template syntax - double braces
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
<h1>{{name}}</h1>
<h1>{{age + 1}}</h1>
<h1>{{gender === 'male' ? '男' : '女'}}</h1>
<h1>{{hobby.join('-->')}}</h1>
</div>
<script src="./vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
name: '刘旭凯',
age: 19,
gender: 'female',
hobby: ['睡觉', '吃饭', '打游戏']
}
});
</script>
</body>
</html>
Template syntax - insert data into the tag attributes
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
<h1 v-bind:title="name">{{name}}</h1>
<h1 v-bind:tie="'我叫' + name + '今年' + age + '岁,爱好' + hobby.join('-->')">{{name}}</h1>
<h1 :title="'我叫' + name + '今年' + age + '岁,爱好' + hobby.join('-->')">{{name}}</h1>
</div>
<script src="./vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
name: '刘旭凯',
age: 19,
gender: 'female',
hobby: ['睡觉', '吃饭', '打游戏']
}
});
</script>
</body>
</html>