Vue 知识点:简单的切换
<div id="root">
<h2>今天天气很{{isHot ? ‘炎热’ : ‘凉爽’}}</h2>
<button @click="changeWeather">切换天气</button>
</div>
<script>
new Vue({
el:"#root",
data:{
isHot:true
},
methods:{
changeWeather() {
this.isHot = !this.isHot
}
}
})
</script>
<div id="root">
<h2>今天天气很{{info}}</h2>
<button @click="changeWeather">切换天气</button>
</div>
<script>
new Vue({
el:"#root",
data:{
isHot:true
},
computed:{
info() {
return this.isHot ? ‘炎热’ : ‘凉爽’
}
},
methods:{
changeWeather() {
this.isHot = !this.isHot
}
}
})
</script>
<div id="root">
<h2>今天天气很{{info}}</h2>
<button @click="isHot ?!isHot">切换天气</button>
</div>
<script>
new Vue({
el:"#root",
data:{
isHot:true
},
computed:{
info() {
return this.isHot ? ‘炎热’ : ‘凉爽’
}
},
})
</script>