在微信小程序中,你可以使用weui組件庫來實現(xiàn)彈出一個確認的popup,并在其中包含圖片和名稱。以下是一個示例代碼:文章來源:http://www.zghlxwxcb.cn/news/detail-581997.html
- 在wxml文件中,添加一個按鈕來觸發(fā)彈出確認popup:
<button bindtap="showPopup">顯示確認Popup</button>
- 在wxss文件中,定義確認popup的樣式:
.popup {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
}
.popup-inner {
width: 80%;
background-color: #fff;
padding: 20px;
text-align: center;
}
.popup-img {
width: 100px;
height: 100px;
margin-bottom: 10px;
}
.popup-name {
font-size: 16px;
font-weight: bold;
margin-bottom: 10px;
}
- 在js文件中,編寫相應(yīng)的邏輯來顯示和隱藏確認popup,并傳遞圖片和名稱數(shù)據(jù):
Page({
data: {
showPopup: false,
popupImage: "",
popupName: "",
},
showPopup() {
const image = "圖片鏈接"; // 替換為實際的圖片鏈接
const name = "產(chǎn)品名稱"; // 替換為實際的產(chǎn)品名稱
this.setData({
showPopup: true,
popupImage: image,
popupName: name,
});
},
hidePopup() {
this.setData({
showPopup: false,
});
},
});
- 在wxml文件中,添加確認popup的代碼:
<!-- 確認popup -->
<view wx:if="{{showPopup}}" class="popup" bindtap="hidePopup">
<view class="popup-inner" bindtap="stopPropagation">
<image class="popup-img" src="{{popupImage}}"></image>
<view class="popup-name">{{popupName}}</view>
<button bindtap="hidePopup">確認</button>
</view>
</view>
在這個示例中,點擊按鈕會觸發(fā)showPopup
函數(shù),該函數(shù)會將showPopup
設(shè)為true
,并傳遞圖片和名稱數(shù)據(jù)。確認popup會顯示圖片、名稱和確認按鈕。當點擊確認按鈕或點擊popup以外的區(qū)域時,hidePopup
文章來源地址http://www.zghlxwxcb.cn/news/detail-581997.html
到了這里,關(guān)于【微信小程序】使用weui組件庫來實現(xiàn)彈出一個確認的彈窗popup,其中包含圖片和名稱的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!