11. vue if 条件判断
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Title</title></head><body><div id="vue"><h2 v-if="isShow"><div>我是if&
·
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="vue">
<h2 v-if="isShow">
<div>我是if</div>
</h2>
<h2 v-else>我是else</h2>
</div>
<div id="score">
<h2 v-if="score>=90">优秀</h2>
<h2 v-else-if="score>=80">良好</h2>
<h2 v-else-if="score>=60">及格</h2>
<h2 v-else>不及格</h2>
</div>
<!--因为上述麻烦,推荐使用computed-->
<div id="computed">
<h2>{{result}}</h2>
</div>
<script src="../js/vue.js"></script>
<script>
const app = new Vue({
el: '#vue',
data: {
message: '你好!华为',
isShow: false
}
});
const score = new Vue({
el: '#score',
data: {
score: 85,
}
});
const computed = new Vue({
el: '#computed',
data: {
score: 85,
scores: 45
},
computed: {
// result:function (){
// 下方简略写法
result() {
let showMessage = '';
if (this.scores >= 90) {
showMessage = '优秀'
} else if (this.scores >= 80) {
showMessage = '良好'
} else if (this.scores >= 70) {
showMessage = '及格'
} else {
showMessage = '不及格'
}
return showMessage;
}
}
});
</script>
</body>
</html>
更多推荐
所有评论(0)