1、Vue简单介绍
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<title>瓜娃子</title>
<script src="../js/vue.js"></script>
</head>
<body>
<div id="app">
<h1>{{message}}</h1>
<h2>{{name}}</h2>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
message: '你好啊,瓜娃子!',
name: '瓜娃子'}
});
</script>
</body>
</html>
2、Vue模板
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<title>瓜娃子</title>
</head>
<body>
<div id="app">
{{message}}
</div>
<script src="js/vue.js"></script>
<script>
const app = new Vue({
el: "#app",
data: {
message: '瓜娃子'
}
});
</script>
</body>
</html>
3、Vue列表展示
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<title>瓜娃子</title>
<script src="js/vue.js"></script>
</head>
<body>
<div id="app">
<ul>
<li v-for="item in movies">{{item}}</li>
</ul>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
message: '你好啊',
movies: ['斗鱼', '星际穿越', '大话西游', '盗梦空间', '少年派','加勒比海盗']
}
});
</script>
</body>
</html>
4、简单案例
<!DOCTYPE html>
<html lang="cn" xmlns:>
<head>
<meta charset="UTF-8">
<title>瓜娃子</title>
<script src="js/vue.js"></script>
</head>
<body>
<div id="app">
<h2>当前计数:{{counter}}</h2>
<!--<button @click="counter++">+</button>-->
<!--<button @click="counter--">-</button>-->
<button @click="addition">+</button>
<button @click="subtraction">-</button>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
counter: 0,
},
methods: {
addition: function () {
console.log('addition被执行了');
this.counter++;
},
subtraction: function () {
console.log('subtraction被执行了');
this.counter--;
}
}
});
</script>
</body>
</html>