第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Vue.js - 綁定到組件的道具未顯示正確的結(jié)果

Vue.js - 綁定到組件的道具未顯示正確的結(jié)果

我的 Vue.js 應(yīng)用程序中有這個(gè) SwitchButton 組件,它有一個(gè)自定義事件“切換”。單擊(切換)按鈕時(shí),切換事件將 isEnabled 設(shè)置為 false 或 true。沒有問題,但是當(dāng)我將父組件中的 isEnabled 綁定到 SwitchButton 子組件以設(shè)置其初始值時(shí),它似乎不起作用。父組件中使用的代碼(將 isEnabled true 作為初始值)<SwitchButton v-model="distSwitch" :isEnabled="true">    <label slot="left">{{ $t('general.dealer') }}</label>    <label slot="right">{{ $t('general.wholesale') }}</label></SwitchButton>開關(guān)按鈕組件:<template>    <div class="switch-button-control">        <div class="switch-button-label">            <slot name="left"></slot>        </div>        <div class="switch-button" :class="{'enabled': isEnabled}" @click="toggle">            <div class="button"></div>        </div>        <div class="switch-button-label">            <slot name="right"></slot>        </div>    </div></template><script>export default {    name: 'SwitchButton',    model: {        prop: 'isEnabled',        event: 'toggle'    },    props: {        isEnabled: {            type: Boolean,            required: true        }    },    methods: {        toggle() {            this.$emit("toggle", !this.isEnabled);        }    },    created() {        /*eslint-disable no-console*/        console.log('isEnabled', this.isEnabled)    }}</script>我希望創(chuàng)建的鉤子中的 console.log 輸出“isEnabled > true”,但它輸出“false”我在這里想念什么?
查看完整描述

1 回答

?
侃侃無極

TA貢獻(xiàn)2051條經(jīng)驗(yàn) 獲得超10個(gè)贊

由于該屬性的值isEnabled是由硬編碼設(shè)置的true,因此從子組件更改它是行不通的。


在父組件中初始化數(shù)據(jù)變量并設(shè)置為屬性可以在這里提供幫助。


模板:


<SwitchButton v-model="distSwitch" :isEnabled="isEnabled" @toggle="toggleIsEnabled">

    <label slot="left">{{ $t('general.dealer') }}</label>

    <label slot="right">{{ $t('general.wholesale') }}</label>

</SwitchButton>

數(shù)據(jù):


data:()=>{

  return {

    isEnabled:true

  }

}

在該部分中創(chuàng)建一個(gè)方法methods:


toggleIsEnabled:function(value){

   this.isEnabled = value;

}

SwitchButton使用自定義事件發(fā)射器從組件發(fā)出的值toggle將觸發(fā)父組件中的回調(diào)函數(shù)toggleIsEnabled。


查看完整回答
反對(duì) 回復(fù) 2022-05-22
  • 1 回答
  • 0 關(guān)注
  • 130 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)