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

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

vue - 通過組件數(shù)組添加時(shí)屬性不響應(yīng)

vue - 通過組件數(shù)組添加時(shí)屬性不響應(yīng)

郎朗坤 2023-08-05 11:04:05
嘿我的代碼看起來像這樣:componentData: [   { name: TestPane, props: { data: this.cars }, id: 1 },   { name: TestPane, props: { data: this.persons }, id: 2 },]<div v-for="component in componentData" :key="component.id">   <component v-bind:is="component.name" v-bind="component.props">   </component></div>props 不是反應(yīng)性的。當(dāng)我在沒有循環(huán)的情況下正常傳遞道具時(shí),:data=cars它們是反應(yīng)性的。但我需要在我的項(xiàng)目中循環(huán)傳遞它們。有任何想法嗎?
查看完整描述

1 回答

?
慕碼人2483693

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

除非您像這樣定義數(shù)據(jù),否則它會(huì)起作用:


data() {

  return {

    cars: [ ... ],

    persons: [ ... ],

    componentData: [

      { name: TestPane, props: { data: this.cars }, id: 1 },

      { name: TestPane, props: { data: this.persons }, id: 2 },

    ]

  }

}

this.cars并且this.persons在您定義 時(shí)不可訪問componentData。使用計(jì)算來維持反應(yīng)性:


new Vue({

  el: "#app",

  data() {

    return {

      cars: [ ... ],

      persons: [ ... ]

    }

  },

  computed: {

    componentData() {

      return [

        { name: TestPane, props: { data: this.cars }, id: 1 },

        { name: TestPane, props: { data: this.persons }, id: 2 },

      ]

    }

  }

});

編輯:這是一個(gè)演示

const TestPane = {

  template: `

    <div class="pane">

      {{ data }}

    </div>

  `,

  props: ['data']

}


/***** APP *****/

new Vue({

  el: "#app",

  data() {

    return {

      cars: ['honda', 'ferrari'],

      persons: ['Bob', 'Mary']

    }

  },

  computed: {

    componentData() {

        return [

        { name: TestPane, props: { data: this.cars }, id: 1 },

        { name: TestPane, props: { data: this.persons }, id: 2 },

      ]

    }

  }

});

.pane {

  padding: 12px;

  background: #dddddd;

  margin: 4px;

}

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">

  <div v-for="component in componentData" :key="component.id">

     <component v-bind:is="component.name" v-bind="component.props">

     </component>

  </div>

</div>


查看完整回答
反對 回復(fù) 2023-08-05
  • 1 回答
  • 0 關(guān)注
  • 144 瀏覽
慕課專欄
更多

添加回答

舉報(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)