vue3-hi

<!DOCTYPE html>
<html lang="zh">

<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">
	<script src="./js/v3.2.8/vue.global.prod.js"></script>
	<title>Document</title>
</head>

<body>
	<div id="app">
		<p>{{msg}}</p>
	</div>
	<script>
		Vue.createApp({
			data() {
				return {
					msg: "hi"
				}
			},
		}).mount("#app")
	</script>

</body>

</html>

  vue三种操作

操作文本、属性、事件

<!DOCTYPE html>
<html lang="zh">

<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">
	<script src="./js/v3.2.8/vue.global.prod.js"></script>
	<title>Document</title>
</head>

<body>
	<!--  -->
	<div id="app">
		<h1 v-bind:title="tit" v-text="msg" v-on:click="showdata"></h1>
	</div>
	<script>
		// 如何操作文本、属性、事件
		Vue.createApp({
			data() {
				return {
					msg: "文本显示",
					tit: "文本绑定"
				}
			},
			methods: {
				showdata() {
					alert("操作事件")
				}
			}
		}).mount("#app")
	</script>

</body>

</html>

  三、计数器自加和自减

<!DOCTYPE html>
<html lang="zh">

<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">
	<script src="./js/v3.2.8/vue.global.prod.js"></script>
	<title>Document</title>
</head>

<body>
	<!--  -->
	<div id="app">
		<h1 v-bind:title="tit" v-text="msg" v-on:click="showdata"></h1>
		<button v-on:click="jianshao">-</button>
		<span v-text="num">0</span>
		<button v-on:click="zengjia">+</button>
	</div>
	<script>
		// 如何操作文本、属性、事件
		Vue.createApp({
			data() {
				return {
					msg: "文本显示",
					tit: "文本绑定",
					num: "0"
				}
			},
			methods: {
				showdata() {
					alert("操作事件")
				},
				zengjia() {
					this.num++;
				},
				jianshao() {
					this.num--;
				}
			}
		}).mount("#app")
	</script>

</body>

</html>

  四、判断语句

<!DOCTYPE html>
<html lang="zh">

<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">
	<script src="./js/v3.2.8/vue.global.prod.js"></script>
	<title>Document</title>
</head>

<body>
	<!--  -->
	<div id="app">
		<h1 v-bind:title="tit" v-text="msg" v-on:click="showdata"></h1>
		<button v-on:click="jianshao">-</button>
		<span v-text="num">0</span>
		<button v-on:click="zengjia">+</button>
	</div>
	<script>
		// 如何操作文本、属性、事件
		Vue.createApp({
			data() {
				return {
					msg: "文本显示",
					tit: "文本绑定",
					num: "0"
				}
			},
			methods: {
				showdata() {
					alert("操作事件")
				},
				zengjia() {
					this.num++;
				},
				jianshao() {
					if (this.num > 0) {
						this.num--;
					}
				}
			}
		}).mount("#app")
	</script>

</body>

</html>

  五、事件简写

v-on:click可以写成@click

posted @ 2022-08-20 21:17  飞雪飘鸿  阅读(28)  评论(0编辑  收藏  举报
https://damo.alibaba.com/ https://tianchi.aliyun.com/course?spm=5176.21206777.J_3941670930.5.87dc17c9BZNvLL