最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序彈窗組件使用詳解

 更新時(shí)間:2022年07月06日 10:01:33   作者:發(fā)呆的薇薇°  
這篇文章主要為大家詳細(xì)介紹了微信小程序彈窗組件的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

介紹

最近在開(kāi)發(fā)小程序應(yīng)用, 發(fā)現(xiàn)小程序當(dāng)中有關(guān)于組件的介紹非常的少, 當(dāng)前自己做的項(xiàng)目當(dāng)中,有出現(xiàn)過(guò)這種情況, 所以自己就封裝了一個(gè)小程序的彈窗組件, 現(xiàn)在把自己的心得分享給大家, 大家一起來(lái)學(xué)習(xí)吧

效果圖

需求背景

項(xiàng)目需求是需要在頁(yè)面上通過(guò)點(diǎn)擊按鈕, 然后彈出彈窗蒙層; 因?yàn)樾⌒〕绦虍?dāng)中經(jīng)常會(huì)用到彈窗, 因此這里我直接將彈窗封裝成了一個(gè)組件, 下次使用的時(shí)候,直接調(diào)用就可以了。

實(shí)現(xiàn)步驟

1、在微信小程序當(dāng)中, 在當(dāng)前項(xiàng)目當(dāng)中, 新建一個(gè)component文件夾, 這個(gè)文件夾專門用來(lái)存放我們要使用的組件, 然后在component文件夾下右擊, 新建文件夾popup, 這里就是我們要用的彈窗組件的文件夾, 再右擊popup文件夾, 選擇新建component, 然后直接輸入popup即可, 小程序內(nèi)部會(huì)為我們自動(dòng)生成.wxss , wxml , json , js等模板文件, 如下圖所示,popup文件夾下的文件為我們的組件,index文件夾下的文件為首頁(yè)上頁(yè)面:

2、popup彈窗組件的代碼部分;

popup.wxml

<view class="wx-popup" style="margin:-{{windowHeight/2}}px 0 0 -{{windowWidth/2}}px" hidden="{{flag}}">
? <view class='popup-container'>
? ? <view class="wx-popup-title">{{title}}</view>
? ? <!-- <view class="wx-popup-con" >{{content}}</view> -->
? ? <view class="wx-popup-con" >
? ? ? <text>{{content_leftText}}</text>
? ? ? <text class="content_money">{{content_money}}</text>
? ? ? <text>{{content_rightText}}</text>
? ? </view>
? ? <view class="wx-popup-btn">
? ? ? <view class="closeBtn">
? ? ? ? <view class="close-popup" bindtap='_close'>
? ? ? ? ? <view>X</view>
? ? ? ? </view>
? ? ? </view>
? ? </view>
? </view>
</view>

popup.wxss

.wx-popup {
? position: fixed;
? left: 0;
? bottom: 0;
? top: 0;
? z-index: 2000;
? width: 100%;
? height: 100%;
? background: rgba(0, 0, 0, .6);
}
.popup-container {
? position: fixed;
? left: 10%;
? top: 20%;
? width: 80%;
? max-width: 600rpx;
? border-radius: 20rpx;
? box-sizing: bordre-box;
? background: #fff;
? z-index: 2000;
}
.wx-popup-title {
? width: 100%;
? padding: 28rpx;
? text-align: center;
? font-size: 36rpx;
? font-weight: bold;
? border-bottom: 5rpx solid #9EA3BA;
? box-sizing: border-box;
}
.wx-popup-con {
? margin: 50rpx 10rpx;
? text-align: center;
? padding: 0 86rpx;
}
.wx-popup-con text {
? padding-bottom: 10rpx;
}
.content_money {
? color: #FFB258;
}
.wx-popup-btn {
? display: flex;
? justify-content: space-around;
? margin-bottom: 40rpx;
}
.wx-popup-btn text {
? display: flex;
? align-items: center;
? justify-content: center;
? width: 30%;
? height: 88rpx;
? border: 2rpx solid #ccc;
? border-radius: 88rpx;
}
.wx-popup-btn .closeBtn {
? position: fixed;
? left: 45%;
? bottom: 30%;
}
.wx-popup-btn .close-popup {
? position: relative;
? height: 80rpx;
? width: 80rpx;
? border: 5rpx solid #fff;
? border-radius: 50%;
}
?.wx-popup-btn .close-popup view {
? ?position: absolute;
? ?left: 30%;
? ?top: 8%;
? ?font-size: 50rpx;
? ?color: #fff;
?}

popup.js

Component({
? options: {
? ? multipleSlots: true // 在組件定義時(shí)的選項(xiàng)中啟用多slot支持
? },
? /**
? ?* 組件的屬性列表
? ?*/
? properties: {
? ? title: { ? ? ? ? ? ?// 屬性名
? ? ? type: String, ? ? // 類型(必填),目前接受的類型包括:String, Number, Boolean, Object, Array, null(表示任意類型)
? ? ? value: '標(biāo)題' ? ? // 屬性初始值(可選),如果未指定則會(huì)根據(jù)類型選擇一個(gè)
? ? },
? ? // 彈窗內(nèi)容
? ? content_leftText: {
? ? ? type: String,
? ? ? value: '內(nèi)容'
? ? },
? ? content_money: {
? ? ? type: String,
? ? ? value: '內(nèi)容'
? ? },
? ? content_rightText: {
? ? ? type: String,
? ? ? value: '內(nèi)容'
? ? },
? },
? /**
? ?* 組件的初始數(shù)據(jù)
? ?*/
? data: {
? ? flag: true,
? },
? /**
? ?* 組件的方法列表
? ?*/
? methods: {
? ? //隱藏彈框
? ? hidePopup: function () {
? ? ? this.setData({
? ? ? ? flag: !this.data.flag
? ? ? })
? ? },
? ? //展示彈框
? ? showPopup () {
? ? ? this.setData({
? ? ? ? flag: !this.data.flag
? ? ? })
? ? },
? ? /*
? ? * triggerEvent 用于觸發(fā)事件
? ? */
? ? _close() {
? ? ? this.triggerEvent("close");
? ? }
? }
})

3、完成模板文件的工作后, 接下來(lái)就是在首頁(yè)當(dāng)中對(duì)這個(gè)組件進(jìn)行配置, 在index文件夾當(dāng)中對(duì)index.json文件進(jìn)行配置, 代碼如下:

4、在首頁(yè)當(dāng)中進(jìn)行使用,代碼如下:

<view class="index_popup">
? ? <view class="btn-area">
? ? ? ? <button type="primary" bindtap="showPopup">點(diǎn)擊預(yù)測(cè)價(jià)錢</button>
? ? </view>
? ? <popup id='popup'
? ? ? ? title='預(yù)測(cè)價(jià)格'?
? ? ? ? content_leftText='您好,預(yù)測(cè)價(jià)格為'
? ? ? ? content_money='{{content_money}}'?
? ? ? ? content_rightText='元 , 預(yù)測(cè)價(jià)格和實(shí)際價(jià)格存在偏差,請(qǐng)耐心等候?qū)I(yè)顧問(wèn)為您服務(wù)。' ?
? ? ? ? bind:close="_close">
? ? </popup>
</view>

5、index.wxss的樣式

.index_popup .btn-area button {
? background-image: linear-gradient(to right, rgba(36, 162, 255), rgba(36, 172, 255), rgba(36, 192, 255));
? font-size: 34rpx;
? font-weight: normal;
? border-radius: 50rpx;
? padding: 18rpx 30rpx;
? margin-top: 100rpx;
}

6、index.js文件里, 配置對(duì)應(yīng)的點(diǎn)擊事件, 還有操作數(shù)據(jù)

// index.js
// 獲取應(yīng)用實(shí)例
const app = getApp()
Page({
? data: {
? ? content_money: '1000萬(wàn)'
? },
? onReady: function () {
? ? //獲得popup組件
? ? this.popup = this.selectComponent("#popup");
? },
? showPopup() {
? ? this.popup.showPopup();
? },
? //取消事件
? _close() {
? ? console.log('你點(diǎn)擊了關(guān)閉按鈕');
? ? this.popup.hidePopup();
? },
? onLoad() {
? },
})

至此, 就全部結(jié)束了, 當(dāng)點(diǎn)擊首頁(yè)index.wxml上的按鈕時(shí), 彈出彈窗組件, 點(diǎn)擊彈窗頁(yè)面下的X按鈕, 可以關(guān)閉彈窗。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

仁化县| 岳普湖县| 株洲县| 彝良县| 昭觉县| 前郭尔| 广东省| 成武县| 自贡市| 桂阳县| 新源县| 韶关市| 广昌县| 马尔康县| 贡觉县| 鄂尔多斯市| 利辛县| 舞阳县| 察隅县| 和顺县| 乐平市| 枝江市| 黔江区| 鲁甸县| 宜兴市| 松原市| 河源市| 襄城县| 永宁县| 中江县| 临汾市| 上高县| 丹东市| 湘西| 南康市| 洞头县| 冀州市| 云龙县| 旌德县| 襄城县| 荆州市|