在进行复杂的逻辑判断的时候,最好不用v-if,v-else-if,而是使用计算属性,来进行判断
<!DOCTYPE html>
<html lang="zh-CN">
<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">
<title>Document</title>
<script src="js/vue.js"></script>
</head>
<body>
<div id="app">
<div v-if="scope > 90">优秀</div>
<div v-else-if="scope>80">良好</div>
<div v-else-if="scope>60">及格</div>
<div v-else>不及格</div>
<h2>{{result}}</h2>
</div>
<script>
var vm = new Vue({
el: '#app',
data: {
scope: 99
},
methods: {
},
computed: {
result() {
let showMsg = '';
if(this.scope >= 90) {
showMsg = '优秀';
}else if (this.scope >= 80) {
showMsg = '良好'
}else if (this.scope >= 60) {
showMsg = '及格'
}else {
showMsg = '不及格'
}
return showMsg;
}
}
});
</script>
</body>
</html>
网友评论