<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id=app>
<p v-if='score>=80'>优秀</p>
<p v-else-if='score>=70'>及格</p>
<p v-else='score<70'>差</p>
<h1>{{show}} 123</h1>
</div>
</body>
</html>
<script src="vue.js"></script>
<script>
const app=new Vue({
el:'#app',
data:{
score:80,
},
computed:{
show(){
let showMessage=''
if(this.score>=80){
showMessage='优秀'
}
else if(this.score>=70){
showMessage='及格'
}
else{
showMessage='差'
}
return showMessage;
}
}
})
</script>
v-if,v-else-if,v-else适合简单的需求,如果要实现复杂的需求还是用计算属性把。