<!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>2.class类名的使用</title>
<script src='./js/vue.js'></script>
<style>
.active {
color: red;
}
.error {
font-size: 30px;
font-weight: bold;
}
</style>
</head>
<body>
<div id="root">
<template v-if="type === 'name'">
<label>用户名:</label>
<input type="text" placeholder="请输入用户名" key="name">
</template>
<template v-if="type === 'mail'">
<label>邮箱:</label>
<input type="text" placeholder="请输入用户名" key="mail">
</template>
<button @click="BtnClickChange"> 点击切换 </button>
</div>
<script>
var app = new Vue({
el: "#root",
data() {
return {
type: "name"
}
},
methods: {
BtnClickChange() {
setTimeout(() => {
this.type = this.type === "name" ? "mail" : "name"
}, 1000)
}
}
})
</script>
</body>
</html>
网友评论