項目中需要對每一個民宿里的每一個房間都需要popup彈出層來介紹每一個房間,房間數據都在一個接口(此民宿)上。
主要代碼如下:
HTML:
<view v-for='(item,index) in roomDetail' :key='index'> <text @tap="togglePopup('bottom', 'popup',index)" >{{item.bedsDescription}}</text> <uni-popup :ref="`popup${index}`" :type="type" style="z-index: 99;"> //彈出層里的內容 </uni-popup> </view>
JS:
togglePopup(type, open,id) {
console.log(this.$refs) //主要還是自己看看refs里的東西來寫,大家都不太一樣
this.$refs[`popup${id}`][0].open()
}