条件渲染—v-if、v-show
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>条件渲染</title>
<script type="text/javascript" src="../js/vue.js"></script>
<style>
img {
width: 100px;
}
</style>
</head>
<body>
<div id="root">
<h2>今天天气很{{isHot ? '炎热' : '凉爽'}}</h2>
<button @click="isHot=!isHot">切换天气</button>
<div v-show="isHot">
<img src="https://s3.ax1x.com/2020/12/13/reC1IA.jpg" /><br /><br />
<span>建议:心静自然就会凉</span>
</div>
<div v-show="!isHot">
<img src="https://s3.ax1x.com/2020/12/13/reCaqg.jpg" /><br /><br />
<span>建议:建议穿秋裤</span>
</div>
<div v-if="isHot">
<img src="https://s3.ax1x.com/2020/12/13/reC1IA.jpg" /><br /><br />
<span>建议:心静自然就会凉</span>
</div>
<div v-else>
<img src="https://s3.ax1x.com/2020/12/13/reCaqg.jpg" /><br /><br />
<span>建议:建议穿秋裤</span>
</div>
</div>
<script>
new Vue({
el: "#root",
data: {
isHot: true,
},
methods: {
changeWeather() {
this.isHot = !this.isHot;
},
},
});
</script>
</body>
</html>