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

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

如何根據(jù) v-for 值在模態(tài)窗口(單擊按鈕時(shí))上獲取所選數(shù)據(jù)?

如何根據(jù) v-for 值在模態(tài)窗口(單擊按鈕時(shí))上獲取所選數(shù)據(jù)?

手掌心 2021-10-21 13:50:17
我是 Vue 的新手,正在使用 Bootstrap 模式來顯示產(chǎn)品信息。我有網(wǎng)格容器,每個(gè)容器都有一個(gè)產(chǎn)品圖片、描述和兩個(gè)按鈕。More details >>單擊其中一個(gè)按鈕 ( ) 時(shí),會(huì)彈出一個(gè)模式窗口,該窗口應(yīng)顯示與其所在網(wǎng)格完全相同的產(chǎn)品描述和圖片。<div id="myapp">  <h1> {{ allRecords() }} </h1>  <div class="wrapper" >    <div class="grid-container" v-for="product in products" v-bind:key="product.ID">      <div class="Area-1">        <img class="product_image" src="https:....single_product.jpg">       </div>      <div class="Area-2">        <div class = "amount">          {{ product.amount }}        </div>        {{ product.Description }}      </div>      <div class="Area-3">        <b-button size="sm" v-b-modal="'myModal'" product_item = "'product'">          More Details >>        </b-button>        <b-modal id="myModal" >          <h1> {{ product.Name }} </h1>          <h3> {{ product.Description }} </h3>        </b-modal>      </div>      <div class="Area-4">        <br><button>Buy</button>      </div>    </div>  </div></div>var app = new Vue({  'el': '#myapp',  data: {    products: "",    productID: 0  },  methods: {    allRecords: function(){      axios.get('ajaxfile.php')        .then(function (response) {          app.products = response.data;        })        .catch(function (error) {          console.log(error);        });    },  }})區(qū)域 1、2 和 4 工作得很好,它們v-for分別根據(jù)每個(gè)網(wǎng)格容器的值和預(yù)期顯示產(chǎn)品數(shù)據(jù)。當(dāng)我點(diǎn)擊More details >>按鈕時(shí),區(qū)域 3 是一個(gè)問題,我只看到一個(gè)褪色的黑屏。我不確定我在這里做錯(cuò)了什么,非常感謝一些幫助。
查看完整描述

3 回答

?
牧羊人nacy

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

添加屬性 selectedProduct,然后在 More Details 按鈕單擊事件上,將當(dāng)前產(chǎn)品分配給 selectedProduct 成員,如下所示:


HTML


  <div class="Area-3">

    <b-button size="sm" v-b-modal="'myModal'" 

             @click="selectProduct(product)">More Details >> </b-button>    

    <b-modal id="myModal">

             <h1> {{ this.selectedProduct.Name }} </h1>

             <h3> {{ this.selectedProduct.Description }} </h3>

    </b-modal>

  </div>

Javascript:


var app = new Vue({

 'el': '#myapp',

 data: {

    products: "",

    productID: 0,

    selectedProduct: {Name: '', Description: '', Amount:0}

 },

 methods: {

   allRecords: function(){

   ...

   },

   selectProduct: function(product)

   {

       this.selectedProduct = product;

   }

   ...

 }


查看完整回答
反對(duì) 回復(fù) 2021-10-21
  • 3 回答
  • 0 關(guān)注
  • 235 瀏覽
慕課專欄
更多

添加回答

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