<!DOCTYPE html>
<html lang="zh">
<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">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<title>Vue自学:v-if和v-else的使用</title>
</head>
<body>
<!-- 方法一,使用v-if/v-eles-if/v-else进行判断 -->
<div id="app">
<h1 v-if="score>=90">优秀</h1>
<h2 v-else-if="score>=80">不错</h2>
<h2 v-else-if="score>=60">及格</h2>
<h2 v-else="score">不及格</h2>
</div>
<div id="app1">
<h1>{{result}}</h1>
</div>
</body>
<script type="text/javascript">
//方法一
const app = new Vue({
el:’#app’,
data:{
score:87
},
})
//方法二
const app1 = new Vue({
el:’#app1’,
data:{
score:’61’
},
computed:{
result(){
let show = ‘’
if(this.score>100){
show = ‘你是不是在玩我?’
} else if(this.score>=90){
show = ‘非常好’
} else if(this.score>=80) {
show = ‘优秀’
} else if(this.score>=60) {
show = ‘及格’
} else {
show = ‘不及格’
}
return show
}
}
})
</script>
</html>