課程
/前端開發(fā)
/Vue.js
/vue2.5入門
請問button上的文字屬性怎么隨著show的屬性改變啊 比如show是true的時候顯示文字是隱藏 false的時候顯示文字是顯示
2018-09-11
源自:vue2.5入門 2-6
正在回答
是盒子模型的,必須能改變其樣式,不然那么多行級元素,沒發(fā)改變樣式,多枯燥啊;謝謝啊看來還是要懂英語啊
<div id="div1">
? ? <h1 v-show="show">{{ msg }}</h1>
? ? <button @click="btn_click">{{ btn_text }}</button>
</div>
<script type="text/javascript">
? ? var div1 = new Vue({
? ? ? ? el: "#div1",
? ? ? ? template: "",
? ? ? ? data: {
? ? ? ? ? ? msg: "Hello World",
? ? ? ? ? ? show: true,
? ? ? ? ? ? btn_text: "隱藏"
? ? ? ? },
? ? ? ? methods: {
? ? ? ? ? ? btn_click: function () {
? ? ? ? ? ? ? ? this.show = !this.show;
? ? ? ? ? ? ? ? if (this.show) {
? ? ? ? ? ? ? ? ? ? this.btn_text = "隱藏";
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? this.btn_text = "顯示";
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? });
</script>
button的內(nèi)容用一個數(shù)據(jù)變量綁定(btn_text),監(jiān)聽按鈕button的點(diǎn)擊事件,事件里判斷h1的狀態(tài)(隱藏顯示),也就是show的值,以此來修改button的test內(nèi)容,也就是btn_text的值
<button?@click="show?=?!show"><span?v-if="show">隱藏</span><span?v-else>顯示</span></button>
data?()?{return?{show:?true}}
鹿年輕 提問者
她沒長發(fā) 回復(fù) 鹿年輕 提問者
<button @click="show = !show"><span v-if="show">按鈕內(nèi)容</span></button>
個人感覺沒這個需求的必要,可以實(shí)現(xiàn)點(diǎn)擊的時候文字發(fā)生改變
舉報(bào)
快速理解Vue編程理念上手Vue2.0開發(fā)。
1 回答vue的計(jì)算屬性
1 回答數(shù)據(jù)中的屬性問題
2 回答2-5計(jì)算屬性
2 回答關(guān)于v-for的各種屬性
1 回答@click不一定屬性值是HandelClick啊 隨便一個名字都可以
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2022-03-25
是盒子模型的,必須能改變其樣式,不然那么多行級元素,沒發(fā)改變樣式,多枯燥啊;謝謝啊看來還是要懂英語啊
2019-02-15
<div id="div1">
? ? <h1 v-show="show">{{ msg }}</h1>
? ? <button @click="btn_click">{{ btn_text }}</button>
</div>
<script type="text/javascript">
? ? var div1 = new Vue({
? ? ? ? el: "#div1",
? ? ? ? template: "",
? ? ? ? data: {
? ? ? ? ? ? msg: "Hello World",
? ? ? ? ? ? show: true,
? ? ? ? ? ? btn_text: "隱藏"
? ? ? ? },
? ? ? ? methods: {
? ? ? ? ? ? btn_click: function () {
? ? ? ? ? ? ? ? this.show = !this.show;
? ? ? ? ? ? ? ? if (this.show) {
? ? ? ? ? ? ? ? ? ? this.btn_text = "隱藏";
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? this.btn_text = "顯示";
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? });
</script>
button的內(nèi)容用一個數(shù)據(jù)變量綁定(btn_text),監(jiān)聽按鈕button的點(diǎn)擊事件,事件里判斷h1的狀態(tài)(隱藏顯示),也就是show的值,以此來修改button的test內(nèi)容,也就是btn_text的值
2018-09-18
2018-09-18
<button @click="show = !show"><span v-if="show">按鈕內(nèi)容</span></button>
2018-09-12
個人感覺沒這個需求的必要,可以實(shí)現(xiàn)點(diǎn)擊的時候文字發(fā)生改變