- v-if v-else
<!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">
<h2 v-if="isShow">
<div>abc</div>
<div>abc</div>
<div>abc</div>
{{message}}
</h2>
<h1 v-else>xianshiwo false</h1>
</div>
<script src="./vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data : {
message : 'nihaoya',
isShow : true
}
})
</script>
</body>
</html>
else-if
<!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}}
<h2 v-if="score>=90">youxiu</h2>
<h2 v-else-if="score>=80">lianghao</h2>
<h2 v-else-if="score>=60">jige</h2>
<h2 v-else>bujige</h2>
</div>
<script src="./vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data : {
score : 55
}
}
})
</script>
</body>
</html>
|