亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在模態中顯示v-for中點擊元素的vue數據

如何在模態中顯示v-for中點擊元素的vue數據

慕斯王 2023-10-14 15:40:29
這就是我的 json 的樣子。我以 v-for 格式顯示其中一堆,并且可以單擊其中一個。我想顯示我在模式中單擊的元素的數據。[{        "id": 1,        "companyName": "test",        "image": "https://mmelektronik.com.pl/wp-content/uploads/2017/10/Insert-logo.jpg.png",        "location": "Warsaw",        "salary": "10000",        "skill": "Junior",        "tags": "test",        "jobDescription": "test",        "title": "UI Designer"    }]    Now I want to access only jobDescription and display it in the modal.b-modal(hide-footer="", :id="id")      template(#modal-title="")        | Information      .d-block.text-center        p {{ want the jobDescription here }}        b-button(variant="primary") Apply這就是我打開模式的方式。  openModal(item) {      this.offer = item;      this.$bvModal.show(this.id);    }成分  b-container    b-card.joblist__post.mt-2(      v-for="offer in filteredOffers",      :id="id"      :key="offer.id",      @click="openModal"    )      .d-flex        .joblist.d-flex.w-100          .joblist__info.d-flex.align-items-center            .company-logo.d-flex.align-items-center.mr-3              b-img.logo(:src="offer.image")            .joblist-name.d-flex.flex-column.text-left              h5.mb-0.font-weight-bold {{ offer.title }}              .located.d-flex.align-items-center.mt-2.justify-content-start                b-icon.mr-2(icon="geo-alt-fill")                p.m-0.text-secondary.joblist-span {{ offer.location }}                b-icon.mx-2(icon="person-fill")                p.m-0.text-secondary.joblist-span {{ offer.companyName }}                b-icon.mx-2(icon="bar-chart-fill")         b-modal(hide-footer="", :id="id")      template(#modal-title="")        | Information       .d-block.text-center        p {{offer.jobDescription}}      b-button(variant="primary") Okexport default {  data() {    return {      search: "",    };  },
查看完整描述

2 回答

?
倚天杖

TA貢獻1828條經驗 獲得超3個贊

您可以采用以下簡單方法。數據中有一個selectedItem屬性,如下所示:


data: {

   return {

      selectedItem: {}

   }

}

并在元素上添加單擊,如下所示,將單擊的對象分配給 selectedItem:


<button v-for="(e, i) in whateverDataArray" :key="i" @click="selectedItem=e">

    {{ e.companyName }}

</button>

然后只需將 selectedItem 作為道具傳遞給模態,這樣當模態出現時,它將顯示被單擊的道具selectedItem!


編輯:在您的情況下,您也應該從 for 循環中刪除模態。此外,您不需要將selectedItemas 屬性傳遞給模式,因為您可以訪問selectedItem.


查看完整回答
反對 回復 2023-10-14
?
MMTTMM

TA貢獻1869條經驗 獲得超4個贊

將您的更改data為:


data() {

  return {

    search: "",

    offer: null

  };

},

在您的模板中使用以下內容:


p {{ offer.jobDescription }}

并將click處理程序更改為:


@click="openModal(offer)"

offer一旦首先在數據中定義并通過點擊傳遞,來自評論的建議就應該起作用。你確實開始offer行動了openModal。


你的模態不應該在里面v-for。把它拿出來并硬編碼一個id:


b-modal(hide-footer="", id="offerModal")

打開它:


this.$bvModal.show('offerModal');


查看完整回答
反對 回復 2023-10-14
  • 2 回答
  • 0 關注
  • 130 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號