VUE通过添加或删除“display:none”属性实现显示切换
<template><div class="hello"><div class="top">3楼</div><div class="middle" :style="display"><div class="bedroom room">2楼卧室</div><div class="bathroom room"&g
·
<template>
<div class="hello">
<div class="top">3楼</div>
<div class="middle" :style="display">
<div class="bedroom room">2楼卧室</div>
<div class="bathroom room">2楼洗手间</div>
</div>
<div class="bottom">Floor 3</div>
<input type="button" @click="toggle()" value="切换">
</div>
</template>
<script>
export default {
name: "HelloWorld",
data() {
return {
display: ""
};
},
methods: {
toggle() {
if (this.display === "display:none") {
this.display = "";
} else {
this.display = "display:none";
}
}
}
};
</script>
<style scoped>
/* ... */
.bedroom {
/* ... */
display: block;
}
/* ... */
</style>
更多推荐
已为社区贡献1条内容
所有评论(0)