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

微信小程序自定義Dialog彈框

 更新時間:2022年07月08日 07:30:04   作者:lluohuih  
這篇文章主要為大家詳細介紹了微信小程序自定義Dialog彈框,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了微信小程序自定義Dialog彈框的具體代碼,供大家參考,具體內(nèi)容如下

一、創(chuàng)建組件

1、在根目錄下自定義一個components文件夾,用來存放自定義的組件。
2、再針對每一個組件創(chuàng)建一個文件夾,用來存放這個組件相關的文件。

3、在指定組件的文件夾中右鍵->新建Component創(chuàng)建組件。這樣創(chuàng)建的目的是在json文件中添加"component": true,將其聲明為一個組件。

下面開始例子:

1、組件頁面 index.wxml

<!-- 確認框 -->
<!-- 遮罩層 -->
<view class="dialog-overlay-view" style="width: {{ windowWidth }}px; height: {{ windowHeight }}px; display: {{ show ? 'block' : 'none' }};"></view>

<view class="col-center" style="width: {{ windowWidth }}px; height: {{ windowHeight }}px; display: {{ show ? 'flex' : 'none' }};">
? ? <view>
? ? ? ? <view class="dialog-content-view">
? ? ? ? ? ? <view>
? ? ? ? ? ? ? ? <text class="dialog-content-text">{{ message }}</text>
? ? ? ? ? ? </view>

? ? ? ? ? ? <view class="operation-view">
? ? ? ? ? ? ? ? <view class="operation-col-view" bindtouchend="onCancel">
? ? ? ? ? ? ? ? ? ? <text class="cancel-text">{{ cancelButtonText }}</text>
? ? ? ? ? ? ? ? </view>
? ? ? ? ? ? ? ? <view class="operation-col-view" bindtouchend="onConfirm">
? ? ? ? ? ? ? ? ? ? <text class="confirm-text">{{ confirmButtonText }}</text>
? ? ? ? ? ? ? ? </view>
? ? ? ? ? ? </view>
? ? ? ? </view>
? ? </view>
</view>

2、組件樣式 index.wxss

/* components/dialog/index.wxss */
.dialog-overlay-view {
? ? background-color: #000000;
? ? opacity: 0.5;
? ? position: fixed;
? ? z-index: 10;
}
.col-center {
? ? position: fixed;
? ? z-index: 11;
? ? display: flex;
? ? flex-direction: column;
? ? justify-content: center;
? ? align-items: center;
}
.dialog-content-view {
? ? width: 210px;
? ? background: #FFFFFF;
? ? border-radius: 8px;
? ? display: flex;
? ? flex-direction: column;
? ? justify-content: center;
? ? padding: 40px 40px 20px 40px;
}
.dialog-content-text {
? ? font-size: 14px;
? ? font-family: PingFangSC-Regular, PingFang SC;
? ? font-weight: 400;
? ? color: #454545;
? ? line-height: 20px;
}

.operation-view {
? ? display: flex;
? ? flex-direction: row;
? ? justify-content: space-between;
? ? margin-top: 30px;
}
.operation-col-view {
? ? height: 36px;
? ? width: 75px;
? ? display: flex;
? ? flex-direction: column;
? ? justify-content: center;
? ? align-items: center;
}

.cancel-text {
? ? height: 14px;
? ? font-size: 14px;
? ? font-family: PingFangSC-Regular, PingFang SC;
? ? font-weight: 400;
? ? color: #999999;
? ? line-height: 14px;
}
.confirm-text {
? ? height: 14px;
? ? font-size: 14px;
? ? font-family: PingFangSC-Regular, PingFang SC;
? ? font-weight: 400;
? ? color: #E63719;
? ? line-height: 14px;
}

3、組件json配置 index.json

{
? ? "component": true,
? ? "usingComponents": {}
}

4、組件頁面的js index.js

// components/dialog/index.js
Component({
? ? options: {
? ? ? ? /**
? ? ? ? ? ? styleIsolation 選項從基礎庫版本 2.6.5 開始支持。它支持以下取值:
? ? ? ? ? ? ? ? isolated 表示啟用樣式隔離,在自定義組件內(nèi)外,使用 class 指定的樣式將不會相互影響(一般情況下的默認值);
? ? ? ? ? ? ? ? apply-shared 表示頁面 wxss 樣式將影響到自定義組件,但自定義組件 wxss 中指定的樣式不會影響頁面;
? ? ? ? ? ? ? ? shared 表示頁面 wxss 樣式將影響到自定義組件,自定義組件 wxss 中指定的樣式也會影響頁面和其他設置了 apply-shared 或 shared 的自定義組件。(這個選項在插件中不可用。)
? ? ? ? ?*/
? ? ? ? styleIsolation: 'isolated'
? ? },
? ? /**
? ? ?* 組件的屬性列表
? ? ?*/
? ? properties: {
? ? ? ? cancelButtonText: {
? ? ? ? ? ? type: String,
? ? ? ? ? ? value: '取消'
? ? ? ? },
? ? ? ? confirmButtonText: {
? ? ? ? ? ? type: String,
? ? ? ? ? ? value: '確定'
? ? ? ? },
? ? ? ? message: {
? ? ? ? ? ? type: String,
? ? ? ? ? ? value: ''
? ? ? ? },
? ? ? ? show: {
? ? ? ? ? ? type: Boolean,
? ? ? ? ? ? value: false,
? ? ? ? },
? ? ? ? confirmCallback: null,
? ? ? ? cancelCallback: null,
? ? },
? ? /**
? ? ?* 組件的初始數(shù)據(jù)
? ? ?*/
? ? data: {
? ? ? ? windowWidth: 0,
? ? ? ? windowHeight: 0,
? ? },
? ? /**
? ? ?* 生命周期函數(shù)
? ? ?*/
? ? ready: function() {
? ? ? ? var _this = this;
? ? ? ? wx.getSystemInfo({
? ? ? ? ? ? success: function(res) {
? ? ? ? ? ? ? ? _this.setData({
? ? ? ? ? ? ? ? ? ? windowWidth: res.windowWidth,
? ? ? ? ? ? ? ? ? ? windowHeight: res.windowHeight,
? ? ? ? ? ? ? ? });
? ? ? ? ? ? }
? ? ? ? });
? ? },
? ? /**
? ? ?* 組件的方法列表
? ? ?*/
? ? methods: {
? ? ? ? onConfirm() {
? ? ? ? ? ? if (this.properties.confirmCallback) {
? ? ? ? ? ? ? ? this.properties.confirmCallback();
? ? ? ? ? ? }
? ? ? ? ? ? this.setData({ show: false });
? ? ? ? },
? ? ? ? onCancel() {
? ? ? ? ? ? if (this.properties.cancelCallback) {
? ? ? ? ? ? ? ? this.properties.cancelCallback();
? ? ? ? ? ? }
? ? ? ? ? ? this.setData({ show: false });
? ? ? ? },
? ? }
});

5、組件js dialog.js

const defaultOptions = {
? ? show: false,
? ? message: '',
? ? selector: '#cus-dialog',
? ? confirmButtonText: '確認',
? ? cancelButtonText: '取消',
? ? confirmCallback: null,
? ? cancelCallback: null,
};
let currentOptions = Object.assign({}, defaultOptions);
function getContext() {
? ? const pages = getCurrentPages();
? ? return pages[pages.length - 1];
}
const Dialog = (options) => {
? ? options = Object.assign(Object.assign({}, currentOptions), options);
? ? const context = options.context || getContext();
? ? const dialog = context.selectComponent(options.selector);
? ? delete options.context;
? ? delete options.selector;
? ? if (dialog) {
? ? ? ? dialog.setData(options);
? ? ? ? wx.nextTick(() => {
? ? ? ? ? ? dialog.setData({ show: true });
? ? ? ? });
? ? }
? ? else {
? ? ? ? console.warn('未找到 cus-dialog 節(jié)點,請確認 selector 及 context 是否正確');
? ? }
};
Dialog.confirm = (options) => Dialog(Object.assign({ showCancelButton: true }, options));
export default Dialog;

6、使用方法

需要用到dialog的頁面引入dialog組件:

{
? ? "usingComponents": {
? ? ? ? "cus-dialog": "../../components/dialog/index"
? ? }
}

頁面加入dialog節(jié)點:

<cus-dialog id="cus-dialog"/>

在頁面的js中彈出dialog窗口:

//引入dialog組件
import Dialog from '../../components/dialog/dialog';

//在代碼中調(diào)用
Dialog.confirm({
? ? message: '彈窗內(nèi)容',
? ? selector: '#cus-dialog',
? ? confirmCallback: function() {
? ? ? ? console.log('確認啦');
? ? }
});

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

相關文章

  • DIV層之拖動、關閉、打開效果代碼

    DIV層之拖動、關閉、打開效果代碼

    非常不錯的效果,適合在當前頁打開測試窗口,圖片等
    2008-09-09
  • 基于JavaScript實現(xiàn)隨機顏色輸入框

    基于JavaScript實現(xiàn)隨機顏色輸入框

    這篇文章主要介紹了基于JavaScript實現(xiàn)隨機顏色輸入框的實例代碼,代碼簡單易懂,非常不錯,需要的朋友參考下吧
    2016-12-12
  • js實現(xiàn)web留言板功能

    js實現(xiàn)web留言板功能

    這篇文章主要為大家詳細介紹了js實現(xiàn)web留言板功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Bootstrap前端開發(fā)案例二

    Bootstrap前端開發(fā)案例二

    Bootstrap前端開發(fā)案例二,這篇文章能夠幫助大家更還好的進行前端開發(fā)Bootstrap,相信大家會愛上Bootstrap
    2016-06-06
  • js控制li的隱藏和顯示實例代碼

    js控制li的隱藏和顯示實例代碼

    下面小編就為大家?guī)硪黄猨s控制li的隱藏和顯示實例代碼。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-10-10
  • JS如何修改數(shù)組對象的Key和指定的值

    JS如何修改數(shù)組對象的Key和指定的值

    這篇文章主要介紹了JS如何修改數(shù)組對象的Key和指定的值,本文通過示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-10-10
  • JavaScript實現(xiàn)簡單的Markdown語法解析器

    JavaScript實現(xiàn)簡單的Markdown語法解析器

    Markdown 是一種輕量級標記語言, 它允許人們使用易讀易寫的純文本格式編寫文檔,然后轉換成有效的 XHTML(或者HTML)文檔。本文將利用JavaScript實現(xiàn)簡單的Markdown語法解析器,感興趣的可以了解一下
    2023-03-03
  • JavaScript中async與await實現(xiàn)原理與細節(jié)

    JavaScript中async與await實現(xiàn)原理與細節(jié)

    這篇文章主要介紹了JavaScript中async與await實現(xiàn)原理與細節(jié),文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-09-09
  • 前端canvas實現(xiàn)電子簽約完成線上簽署功能

    前端canvas實現(xiàn)電子簽約完成線上簽署功能

    最近發(fā)現(xiàn)現(xiàn)在租房還是簽合同,越來越多采用電子簽約的方式進行,好處不用多說節(jié)約成本,節(jié)約時間,下面我們來看看使用canvas實現(xiàn)電子簽約完成線上簽署功能
    2025-01-01
  • JavaScript實現(xiàn)隨機五位數(shù)驗證碼

    JavaScript實現(xiàn)隨機五位數(shù)驗證碼

    這篇文章主要為大家詳細介紹了JavaScript實現(xiàn)隨機五位數(shù)驗證碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-09-09

最新評論

原阳县| 汝州市| 乐至县| 若羌县| 特克斯县| 黄平县| 枞阳县| 崇州市| 岱山县| 西峡县| 运城市| 南溪县| 临沧市| 新安县| 寿宁县| 江华| 新郑市| 台东市| 满洲里市| 赤峰市| 抚顺县| 福安市| 泰兴市| 额济纳旗| 满洲里市| 鹤岗市| 米林县| 宜君县| 张家界市| 马鞍山市| 抚州市| 武陟县| 富川| 沈阳市| 泽普县| 湛江市| 九台市| 个旧市| 驻马店市| 邯郸市| 长沙市|