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

微信小程序自定義組件實(shí)現(xiàn)單選功能

 更新時(shí)間:2022年07月19日 10:05:46   作者:HZR_497  
這篇文章主要為大家詳細(xì)介紹了微信小程序自定義組件實(shí)現(xiàn)單選功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了微信小程序自定義組件實(shí)現(xiàn)單選的具體代碼,供大家參考,具體內(nèi)容如下

效果圖:

調(diào)用部分(例如在index頁面)

index.wxml

<view catchtap="showSinger">
? 單選按鈕
? <singer id="singer" bind:singerCancel="_singerCancel" bind:singerConfirm="_singerConfirm" singerContent='{{singerContent}}' singer_list="{{singer_list}}">
? </singer>
</view>

index.js

Page({
?
? /**
? ?* 頁面的初始數(shù)據(jù)
? ?*/
? data: {
??
? ? singerContent: '單選按鈕',
? ? singer_list: [{
? ? ? key: "100以下",
? ? ? name: "100以下"
? ? }, {
? ? ? key: "200以下",
? ? ? name: "200以下"
? ? }, {
? ? ? key: "300以下",
? ? ? name: "300以下"
? ? }, {
? ? ? key: "400以下",
? ? ? name: "400以下"
? ? }, {
? ? ? key: "500以下",
? ? ? name: "500以下"
? ? }, {
? ? ? key: "600以下",
? ? ? name: "600以下"
? ? }, {
? ? ? key: "700以下",
? ? ? name: "700以下"
? ? }, {
? ? ? key: "800以下",
? ? ? name: "800以下"
? ? }, {
? ? ? key: "900以下",
? ? ? name: "900以下"
? ? }, {
? ? ? key: "1000以下",
? ? ? name: "1000以下"
? ? }],
?
? ?
? },
?
? /**
? ?* 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成
? ?*/
? onReady: function() {
? ? //獲得input_select組件
? ? this.input_select = this.selectComponent("#input_select");
?
? ? //獲得singer組件 單選
? ? this.singer = this.selectComponent("#singer");
?
? ? //獲得multiple組件 ?多選
? ? this.multiple = this.selectComponent("#multiple");
? },
?
?
? //**************************************單選自定義組件部分************************
? showSinger: function() {
? ? this.singer.showSinger();
? },
?
? //取消事件
? _singerCancel() {
? ? console.log('你點(diǎn)擊了取消');
? ? this.singer.hideSinger();
? },
? //確認(rèn)事件
? _singerConfirm(e) {
? ? console.log('你點(diǎn)擊了確定==', e.detail);
? ? this.singer.hideSinger();
? },
?
})

index.json

{
? "usingComponents": {
? ? "singer": "/component/selector/singer/singer",
? }
}

自定義組件部分(命名為singer)

singer.wxml

<!--component/selector/singer.wxml-->
<view class='singer-bg' wx:if="{{isShow}}">
? <view class='singer-body'>
? ? <view class='singer-body-name'>
? ? ? <view class='singer-body-name-line'></view>
? ? ? <view class='singer-body-name-txt'>{{singerContent}}</view>
? ? ? <view class='singer-body-name-line'></view>
? ? </view>
? ? <view class='singer-body-list'>
? ? ? <block wx:for="{{singer_list}}" wx:for-item="item" wx:key="unique">
? ? ? ? <view class='list-item-choosed' wx:if="{{choose_type==item.key}}" data-key='{{item.key}}' bindtap='clicktype'>
? ? ? ? ? <view class='item-choosed-txt'>{{item.name}}</view>
? ? ? ? </view>
? ? ? ? <view class='list-item' data-key='{{item.key}}' bindtap='clicktype' wx:else>
? ? ? ? ? <view class='item-txt'>{{item.name}}</view>
? ? ? ? </view>
? ? ? </block>
? ? </view>
? ? <view class='singer-body-kongbai'></view>
? ? <view class='singer-body-icon'>
? ? ? <view class='icon-left' catchtap='_singerCancel'>重置</view>
? ? ? <view class='icon-right' catchtap='_singerConfirm'>確定</view>
? ? </view>
? </view>
</view>

singer.js

Component({
? /**
? ?* 組件的屬性列表
? ?*/
? properties: {
? ? //標(biāo)題文字
? ? singerContent: {
? ? ? type: String,
? ? ? value: ''
? ? },
? ? singer_list: {
? ? ? type: Array,
? ? ? value: [{
? ? ? ? key: '',
? ? ? ? name: ''
? ? ? }, ]
? ? }
? },
?
? /**
? ?* 組件的初始數(shù)據(jù)
? ?*/
? data: {
? ? isShow: false,
? ? choose_type: "",
? },
? onLoad: function() {
? ? this.properties
? },
? /**
? ?* 組件的方法列表
? ?*/
? methods: {
? ? clicktype: function(e) {
? ? ? this.setData({
? ? ? ? choose_type: e.currentTarget.dataset.key,
? ? ? })
? ? },
? ? //隱藏彈框
? ? hideSinger: function() {
? ? ? this.setData({
? ? ? ? isShow: false,
? ? ? ? json: {
? ? ? ? ? start: "",
? ? ? ? ? end: "",
? ? ? ? }
? ? ? })
? ? },
? ? //展示彈框
? ? showSinger: function() {
? ? ? this.setData({
? ? ? ? isShow: true,
? ? ? })
? ? },
? ? /*
? ? ?* 內(nèi)部私有方法建議以下劃線開頭
? ? ?* triggerEvent 用于觸發(fā)事件
? ? ?*/
? ? _singerCancel() {
? ? ? //觸發(fā)取消回調(diào)
? ? ? this.triggerEvent("singerCancel")
? ? },
? ? _singerConfirm() {
? ? ? //觸發(fā)成功回調(diào)
? ? ? this.triggerEvent("singerConfirm", this.data.choose_type);
? ? }
? }
})

singer.json

{
? "component": true
}

singer.wxss

/* component/selector/singer.wxss */
?
.singer-bg {
? width: 100%;
? height: 100%;
? position: fixed;
? top: 0;
? left: 0;
? z-index: 9999;
? background: rgba(0, 0, 0, 0.5);
}
?
.singer-bg .singer-body {
? min-width: 100%;
? width: 100%;
? height: 968rpx;
? max-height: 968rpx;
? background: rgba(255, 255, 255, 1);
? border-radius: 20px 20px 0px 0px;
? position: absolute;
? left: 0;
? bottom: 0;
}
?
.singer-bg .singer-body .singer-body-name {
? width: 100%;
? display: flex;
? flex-wrap: nowrap;
? justify-content: center;
? align-items: center;
? margin-top: 60rpx;
? margin-bottom: 50rpx;
}
?
.singer-bg .singer-body .singer-body-name .singer-body-name-line {
? width: 260rpx;
? border-bottom: 2rpx solid rgba(240, 240, 240, 1);
}
?
.singer-bg .singer-body .singer-body-name .singer-body-name-txt {
? height: 48rpx;
? font-size: 34rpx;
? font-family: PingFangSC-Medium;
? font-weight: 500;
? color: rgba(0, 0, 0, 1);
? line-height: 48rpx;
? margin-left: 10rpx;
? margin-right: 10rpx;
}
?
.singer-bg .singer-body .singer-body-list {
? width: 100%;
? max-height: 650rpx;
? display: flex;
? flex-direction: row;
? align-items: flex-start;
? flex-wrap: wrap;
? padding: 0rpx 10rpx 0rpx 40rpx;
? overflow: auto;
}
?
.singer-bg .singer-body .singer-body-list .list-item-choosed {
? width: 182rpx;
? height: 70rpx;
? display: flex;
? justify-content: center;
? align-items: center;
? background: rgba(191, 213, 236, 1);
? border-radius: 6rpx;
? margin-right: 30rpx;
? margin-bottom: 20rpx;
? padding: 0rpx 10rpx 0rpx 10rpx;
}
?
.singer-bg .singer-body .singer-body-list .list-item-choosed .item-choosed-txt {
? font-size: 30rpx;
? font-family: PingFangSC-Regular;
? font-weight: 400;
? line-height: 70rpx;
? color: rgba(0, 89, 179, 1);
? display: -webkit-box;
? word-break: break-all;
? text-overflow: ellipsis;
? overflow: hidden;
? -webkit-box-orient: vertical;
? -webkit-line-clamp: 1;
}
?
/**/
?
.singer-bg .singer-body .singer-body-list .list-item {
? width: 182rpx;
? height: 70rpx;
? display: flex;
? flex-wrap: nowrap;
? justify-content: center;
? align-items: center;
? background: rgba(240, 240, 240, 1);
? border-radius: 6rpx;
? margin-right: 30rpx;
? margin-bottom: 20rpx;
? padding: 0rpx 10rpx 0rpx 10rpx;
}
?
.singer-bg .singer-body .singer-body-list .list-item ?.item-txt {
? font-size: 30rpx;
? font-family: PingFangSC-Regular;
? font-weight: 400;
? color: rgba(51, 51, 51, 1);
? line-height: 70rpx;
? display: -webkit-box;
? word-break: break-all;
? text-overflow: ellipsis;
? overflow: hidden;
? -webkit-box-orient: vertical;
? -webkit-line-clamp: 1;
}
?
.singer-bg .singer-body .singer-body-kongbai {
? width: 100%;
? height: 120rpx;
}
?
.singer-bg .singer-body .singer-body-icon {
? width: 100%;
? height: 110rpx;
? display: flex;
? flex-wrap: nowrap;
? justify-content: space-between;
? position: fixed;
? bottom: 0;
? z-index: 9999999999;
? background: rgba(255, 255, 255, 1);
}
?
.singer-bg .singer-body .singer-body-icon .icon-left {
? width: 374rpx;
? height: 110rpx;
? background: rgba(0, 89, 179, 0.1);
? font-size: 36rpx;
? font-family: PingFangSC-Regular;
? font-weight: 400;
? color: rgba(0, 89, 179, 1);
? line-height: 50rpx;
? display: flex;
? align-items: center;
? justify-content: center;
}
?
.singer-bg .singer-body .singer-body-icon .icon-right {
? width: 374rpx;
? height: 110rpx;
? background: rgba(0, 89, 179, 1);
? font-size: 36rpx;
? font-family: PingFangSC-Regular;
? font-weight: 400;
? color: rgba(255, 255, 255, 1);
? line-height: 50rpx;
? display: flex;
? align-items: center;
? justify-content: center;
}

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

相關(guān)文章

最新評論

正宁县| 孟津县| 隆化县| 思茅市| 青龙| 永济市| 红桥区| 讷河市| 客服| 夏河县| 高邮市| 汶上县| 富裕县| 留坝县| 闵行区| 元朗区| 铜山县| 太湖县| 星座| 文水县| 肥乡县| 斗六市| 揭西县| 濮阳市| 攀枝花市| 通化县| 隆林| 恩施市| 玛纳斯县| 乌苏市| 承德市| 抚宁县| 贵港市| 佛学| 额敏县| 新蔡县| 峨眉山市| 龙陵县| 信阳市| 连州市| 会宁县|