微信小程序?qū)崿F(xiàn)簡(jiǎn)易封裝彈窗
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)簡(jiǎn)易封裝彈窗的具體代碼,供大家參考,具體內(nèi)容如下
1.建立組件文件夾
2.編寫組件內(nèi)容
?<!--index.wxml--> <view class="container"> ? <text>demo 01 heihzi</text> ? <view bindtap="onDialog">點(diǎn)擊 打開彈窗</view> </view> <dialog id="dialog" title="查看詳情"> ? <scroll-view class="p-b min-ht" scroll-y style="height: 700rpx;"> ? ? <view class="dia-warp"> ? ? ? <text>詳情信息</text> ? ? ? <view wx:for="{{20}}" wx:key="index">{{item}}</view> ? ? </view> ? </scroll-view> </dialog>
// components/dialong/index.js Component({ ? /** ? ?* 組件的屬性列表 ? ?*/ ? properties: { ? ? title: { ? ? ? type: String ? ? } ? }, ? /** ? ?* 組件的初始數(shù)據(jù) ? ?*/ ? data: { ? ? show: false, ? ? zIndex: 0, ? ? ablClickMask: true, ? ? hasClsBtn: false, ? ? title: '' ? }, ? /** ? ?* 組件的方法列表 ? ?*/ ? methods: { ? ? open(params, cb, fb) { ? ? ? params = params || {} ? ? ? this.setData({ ? ? ? ? show: true, ? ? ? ? zIndex: params.zIndex || 0 ? ? ? }) ? ? ? this.data._cb = cb ? ? ? this.data._fb = fb ? ? }, ? ? close() { ? ? ? this.setData({ ? ? ? ? show: false ? ? ? }) ? ? }, ? ? onMaskHide() { ? ? ? if (this.data.ablClickMask) { ? ? ? ? this.close() ? ? ? ? this.triggerEvent('maskEvt') ? ? ? } ? ? } ? } })
樣式一定要加 不然組件彈窗出不來(lái)
/* components/dialong/index.wxss */ /* 彈窗 */ .pop { ? width: 80%; ? background: #fff; ? border-radius: 12rpx; ? height: auto; ? max-height: 70vh; ? margin: auto; ? position: absolute; ? position: fixed; ? left: 0; ? right: 0; ? top: 20vh; ? opacity: 0; ? overflow: hidden; ? transform: scale(0.5, 0.5); ? -webkit-transform: scale(0.5, 0.5); ? transition: all 0.2s ease; ? -webkit-transition: all 0.2s ease; } .pop-enter { ? opacity: 1; ? transform: scale(1, 1); ? -webkit-transform: scale(1, 1); ? z-index: 1000; } .mask { ? width: 100vw; ? height: 100vh; ? box-sizing: border-box; ? background: rgba(0, 0, 0, 0.6); ? position: fixed; ? top: 0; ? bottom: 0; ? left: 0; ? right: 0; ? z-index: 700; } .title { ? text-align: center; ? padding: 20rpx 0; ? border-bottom: 1rpx solid #CCC; }
組件的引入 index .json
?"usingComponents" : { ? ? "dialog" : "/components/dialong/index" ? },
3.頁(yè)面中使用
<!--index.wxml--> <view class="container"> ? <text>demo 01 heihzi</text> ? <view bindtap="onDialog">點(diǎn)擊 打開彈窗</view> </view> <dialog id="dialog" title="查看詳情"> ? <scroll-view class="p-b min-ht" scroll-y style="height: 700rpx;"> ? ? <view class="dia-warp"> ? ? ? <text>詳情信息</text> ? ? ? <view wx:for="{{20}}" wx:key="index">{{item}}</view> ? ? </view> ? </scroll-view> </dialog>
//index.js //獲取應(yīng)用實(shí)例 const app = getApp() Page({ ? data: { ? }, ? onLoad: function () { ?? ? }, ? onDialog () { ? ? console.log('打開我啊') ? ? this.dialog.open() ? }, ? onReady () { ? ? this.dialog = this.selectComponent("#dialog") ? } })
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
webpack.DefinePlugin與cross-env區(qū)別詳解
這篇文章主要介紹了webpack.DefinePlugin與cross-env區(qū)別詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02原生js與jQuery實(shí)現(xiàn)簡(jiǎn)單的tab切換特效對(duì)比
這篇文章主要通過(guò)原生js與jQuery實(shí)現(xiàn)簡(jiǎn)單的tab切換特效對(duì)比介紹了js與jQuery之間的區(qū)別,有需要的小伙伴可以參考下。2015-07-07淺談javascript中的 “ && ” 和 “ || ”
本文主要介紹了Javascript中的 “ && ” 和 “ || ”的相關(guān)知識(shí)。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-02-02基于JS實(shí)現(xiàn)禁止查看源碼及獲取鍵盤的按鍵值
這篇文章主要介紹了基于JS實(shí)現(xiàn)禁止查看源碼及獲取鍵盤的按鍵值,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-02-02兼容IE,firefox的獲取節(jié)點(diǎn)的文本值的javascript代碼
javascript獲取節(jié)點(diǎn)的文本值,已經(jīng)考慮了兼容性。大家可以放心使用。注意了這里的兼容沒(méi)有使用innerText,如果要使用兼容innerText,請(qǐng)參考腳本之家以前發(fā)布的文章。2009-12-12JavaScript中的noscript元素屬性位置及作用介紹
Javascript插入到XHTML中要使用script元素,使用這個(gè)元素可以把Javascript嵌入到XHTML頁(yè)面中,讓腳本與標(biāo)記混合在一起,感興趣的朋友可以了解下2013-04-04