<template> <div id="main"> <span v-if="title">aaa</span> <span v-else>bbb</span> <button @click="clickme">aaaaa</button> </div></template><script>export default{ data () { return { title: true, showIn: false, imageSrc: 'http://www.baidu.com', classA: 'aaa', classB: 'bbb', num: 0 } }, methods: { clickme () { if (this.title === true) { this.title = false console.log(this.title) } else { this.title = true console.log(this.title) } } }}</script>
2 回答
慕容森
TA贡献1853条经验 获得超18个赞
qq_花开花谢_0
TA贡献1835条经验 获得超7个赞
请参照这个(简单暴力):
<template>
<div id="main">
<span v-if="title">aaa</span>
<span v-else>bbb</span>
<button @click="clickme">aaaaa</button>
</div>
</template>
<script>
export default{
data () {
return {
title: true
}
},
methods: {
clickme () {
this.title = !this.title;
}
}
}
</script>
添加回答
举报
0/150
提交
取消