国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【微信小程序】記一次自定義微信小程序組件的思路

這篇具有很好參考價(jià)值的文章主要介紹了【微信小程序】記一次自定義微信小程序組件的思路。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

最近來個(gè)需求,要求給小程序的 modal 增加個(gè)關(guān)閉按鈕,上網(wǎng)一查發(fā)現(xiàn)原來 2018 年就有人給出解決方案了,于是總結(jié)下微信小程序自定義組件的思路:一句話,用 wxml + css實(shí)現(xiàn)和原生組件類似的樣式和效果,之后用 JS 實(shí)現(xiàn)類似原生組件的功能。

比如 modal 組件,觀察可以得出就是個(gè)在頁面頂層顯示的 mask + div。modal 的顯示與否可以通過 wx-if 控制,需要注意的點(diǎn)是 modal 顯示的時(shí)候要有動(dòng)畫效果,這個(gè)功能可以通過 css animation 實(shí)現(xiàn)。

自定義 modal 的示例代碼:
WXML:

<view wx-if="{{cusModalShow}}" bindtap="handleCusModalMaskTap" class="cus-modal">
    <view catchtap class="cus-modal__content">
        <view class="cus-modal__close-btn" bindtap="handleCusModalMaskTap">
            ×
        </view>
        <view class="cus-modal__content-title">
            <text>提示</text>
        </view>
        <view class="cus-modal__content-text">
            <text>請(qǐng)確認(rèn)操作</text>
        </view>
        <view class="cus-modal__content-buttons">
            <text bindtap="handleCusModalCancel" class="cus-modal__content-button-cancel">取消</text>
            <text bindtap="handleCusModalConfirm" class="cus-modal__content-button-confirm">確認(rèn)</text>
        </view>
    </view>
</view>

CSS:

@keyframes fade-in {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

.cus-modal {
    display: flex;
    align-items: center;
    justify-content: center;

    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);

    animation: fade-in 0.3s ease;
}

.cus-modal__content {
    background-color: white;
    border-radius: 15px;
    width: 80%;
    position: relative;
}

.cus-modal__close-btn {
    color: rgb(179, 179, 179);
    font-size: 1.5rem;
    position: absolute;
    right: 0.5rem;
    top: 0.1rem;
}

.cus-modal__content-title,
.cus-modal__content-text {
    font-size: 1.1rem;
    text-align: center;
}

.cus-modal__content-title {
    font-weight: bold;
    margin: 40px 0 20px 0;
}

.cus-modal__content-text {
    color: rgb(179, 179, 179);
    margin-bottom: 40px;
}

.cus-modal__content-buttons {
    display: flex;
}

.cus-modal__content-buttons {
    border-top: 1px solid rgb(245, 245, 245);
}

.cus-modal__content-buttons>text {
    flex: 1;
    text-align: center;
    padding: 20px 30px;
    border-right: 1px solid rgb(245, 245, 245);
    box-sizing: border-box;
    height: 60px;
}

.cus-modal__content-buttons>text:last-child {
    border-right: none;
}

.cus-modal__content-button-cancel {
    font-weight: bold;
}

.cus-modal__content-button-confirm {
    font-weight: bold;
    color: rgb(90, 117, 155);
}

自定義 Picker:
這里實(shí)際只是模擬了原生 Picker 從底部彈入的效果,具體內(nèi)容可以通過放在里面的組件實(shí)現(xiàn)。
WXML

<view bindtap="closeBottomPicker" wx-if="{{cusPickerShow}}" class="cus-picker">
    <view class="cus-picker__mask"></view>
    <view catchtap class="cus-picker__content">
        <!-- <view class="cus-picker__header">
            <text class="cus-pick__header__btn-cancel">取消</text>
            <text class="cus-pick__header__btn-confirm">確定</text>
        </view> -->
        <some-component bindclose="handleCarFilterClose"></some-component>
    </view>
</view>

CSS:文章來源地址http://www.zghlxwxcb.cn/news/detail-666213.html

@keyframes slide-up-from-bottom {
    0% {
        transform: translateY(100%);
    }

    100% {
        transform: translateY(0);
    }
}

@keyframes fade-in {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

.cus-picker {
    z-index: 114514;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.cus-picker__mask {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fade-in 0.3s ease;
}

.cus-picker__content {
    box-sizing: border-box;
    position: absolute;
    height: 50%;
    width: 100%;
    bottom: 0;
    background-color: white;
    animation: slide-up-from-bottom 0.3s ease;
}

.cus-picker__header {
    display: flex;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid rgb(245, 245, 245);
    font-size: 16px;
}

.cus-pick__header__btn-cancel {
    color: rgb(127, 127, 127);
}

.cus-pick__header__btn-confirm {
    color: rgb(0, 196, 105);
}

到了這里,關(guān)于【微信小程序】記一次自定義微信小程序組件的思路的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【微信小程序】自定義組件(一)

    組件的創(chuàng)建與引用 1、創(chuàng)建組件 在項(xiàng)目的根目錄中,鼠標(biāo)右鍵,創(chuàng)建 components - test 文件夾 在新建的components - test文件夾上,鼠標(biāo)右鍵,點(diǎn)擊\\\"新建Component\\\" 鍵入組件的名稱之后回車,會(huì)自動(dòng)生成組件對(duì)應(yīng)的4個(gè)文件,后綴名分別為 js, json, .wxml 和.Wxss 注意:為了保證目錄結(jié)構(gòu)的清

    2024年02月05日
    瀏覽(107)
  • 【微信小程序】自定義組件(三)

    插槽 1、什么是插槽 在自定義組件的wxml結(jié)構(gòu)中,可以提供一個(gè) solot 節(jié)點(diǎn)(插槽),用于承載組件使用者提供的wxml結(jié)構(gòu) 2、單個(gè)插槽 在小程序中,默認(rèn)每個(gè)自定義組件中只允許使用一個(gè) slot 進(jìn)行占位,這種個(gè)數(shù)上的限制叫做單個(gè)插槽。 3、定義多個(gè)插槽 父子組件之間的通信

    2024年02月04日
    瀏覽(112)
  • 微信小程序-自定義組件的使用

    微信小程序-自定義組件的使用

    1.使用步驟 創(chuàng)建組件 注冊(cè)組件 使用組件 1創(chuàng)建組件 通常將項(xiàng)目中的組件都放在一個(gè)獨(dú)立的目錄下,并且一般就給這個(gè)文件夾取名為:components 。 右鍵點(diǎn)擊MyTest,點(diǎn)擊新建Component,填寫組件名之后會(huì)自動(dòng)創(chuàng)建4個(gè)同名的文件. 注意: 組件和頁面的結(jié)構(gòu)是一致的,但也是有區(qū)別: 組件

    2024年02月03日
    瀏覽(93)
  • 微信小程序之自定義組件

    微信小程序之自定義組件

    目錄 自定義組件 — 樣式 ?自定義組件—數(shù)據(jù)、方法和屬性 數(shù)據(jù)監(jiān)聽器 純數(shù)據(jù)字段 組件的生命周期 組件所在頁面的生命周期 數(shù)據(jù)監(jiān)聽器-案例 插槽 組件通信-父子組件之間的通信 ①在項(xiàng)目的根目錄中,鼠標(biāo)右鍵,創(chuàng)建 components - test 文件夾 ②在新建的 components - test 文件夾上

    2024年02月07日
    瀏覽(93)
  • 微信小程序?qū)W習(xí)筆記(四)——自定義組件

    微信小程序?qū)W習(xí)筆記(四)——自定義組件

    創(chuàng)建組件 在根目錄下創(chuàng)建 components 文件夾 右鍵點(diǎn)擊 components 文件夾,選擇 新建 Component ,就會(huì)自動(dòng)生成 .wxml、.wxss、.js、.json 文件 引用組件 組件的引用方式分為“ 局部引用 ”和“ 全局引用 ”,故名思義: 局部引用 :組件只能在當(dāng)前被引用的頁面內(nèi)使用 全局引用 :組件

    2024年02月16日
    瀏覽(119)
  • 微信小程序自定義日期選擇器組件

    微信小程序自定義日期選擇器組件

    默認(rèn)開始時(shí)間為當(dāng)天 最大結(jié)束時(shí)間為當(dāng)天 默認(rèn)結(jié)束時(shí)間為開始時(shí)間的10后 wxml? ?js wxss

    2024年02月11日
    瀏覽(88)
  • 微信小程序之自定義組件開發(fā)

    微信小程序之自定義組件開發(fā)

    從小程序基礎(chǔ)庫版本 1.6.3 開始,小程序支持簡(jiǎn)潔的組件化編程。所有自定義組件相關(guān)特性都需要基礎(chǔ)庫版本 1.6.3 或更高。開發(fā)者可以將頁面內(nèi)的功能模塊抽象成自定義組件,以便在不同的頁面中重復(fù)使用;也可以將復(fù)雜的頁面拆分成多個(gè)低耦合的模塊,有助于代碼維護(hù)。自

    2024年02月02日
    瀏覽(105)
  • 微信小程序|自定義彈窗組件

    微信小程序|自定義彈窗組件

    2024年02月12日
    瀏覽(87)
  • 微信小程序- component 自定義組件及引用

    微信小程序- component 自定義組件及引用

    一、自定義組件 1、根目錄下創(chuàng)建一個(gè) Components 文件夾 2、在 Components 文件夾中創(chuàng)建一個(gè)文件夾(文件夾名稱為組件名稱),例如組件名稱為Myheader ?3、點(diǎn)擊Myheader 文件夾,右鍵選擇 新建Component, 并命名為Myheader ? 4、在 Myheader.wxml 和 Myheader.scss 中寫對(duì)應(yīng)的內(nèi)容 二、引用自定

    2024年02月04日
    瀏覽(24)
  • 微信小程序子頁面自定義tabbar組件

    微信小程序子頁面自定義tabbar組件

    有時(shí)候微信小程序會(huì)遇到代碼合并,就比如把B小程序代碼遷移到A小程序,要使得B作為A小程序的一個(gè)子頁面子功能。因?yàn)楸旧硇〕绦蚨加衪abbar,原來B也有,這時(shí)候就要給B子功能自定義一個(gè)tabbar底部導(dǎo)航欄。(注意,這個(gè)不是微信小程序自定義tabBar,不需要app.json中設(shè)置一個(gè)

    2024年02月08日
    瀏覽(26)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包