亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

uniapp中uni-popup的具體使用

 更新時(shí)間:2023年06月25日 10:05:18   作者:棒怡情  
本文主要介紹了uniapp中uni-popup的具體使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

uni-pop彈出層組件,在應(yīng)用中彈出一個(gè)消息提示窗口、提示框等,可以設(shè)置彈出層的位置,是中間、底部、還是頂部。

如下圖效果所示:白色區(qū)域則為彈出的pop層。

一、 創(chuàng)建一個(gè)自定義組件:

1.項(xiàng)目中安裝下載uni-pop插件。

2.把pop內(nèi)容單獨(dú)寫個(gè)組件。這里放到 components下。 type="bottom"指的pop展示所在屏幕的位置。

<template>
    <view>
        <uni-popup ref="cityPhonePop" type="bottom">
            <view class="popup-content">
                <view class="contentPop columnPop">
                    <block v-for="(item,index) in array">
                        <view class="columnPop itemPop" @click="callPhone(item)">
                            <text>{{item.name}}:{{item.phone}}</text>
                        </view>
                    </block>
                    <view style="background:#f3f3f3;height:10rpx;width: 100%;"></view>
                    <view
                        style="min-height: 70rpx;display: flex; align-items: center;width: 100%;justify-content: center;"
                        @click="closeInfoPop">
                        <text>取消</text>
                    </view>
                </view>
            </view>
        </uni-popup>
    </view>
</template>

在methods里面定義,用到的js方法:

    methods: {
            closeInfoPop() {
                this.$refs.cityPhonePop.close()
            },
            //撥打電話
            callPhone(item) {
                var that = this;
                uni.makePhoneCall({
                    phoneNumber: item.phone,
                    // phoneNumber: '025-83582006',
                    success: (res) => {
                        console.log('調(diào)用成功!')
                        that.closeInfoPop();
                    },
                    fail: (res) => {
                        console.log('調(diào)用失敗!')
                    }
                });
            },
            open() {
                //cityPhonePop是上面布局定義的uni-pop 的ref后面的名稱, this.$refs.cityPhonePop.open()則打開pop展示。
                this.$refs.cityPhonePop.open()
            },
            close() {
                this.$refs.cityPhonePop.close()
            }
        }

此組件則定義完成。

二、頁面中使用上面創(chuàng)建的自定義組件:

1.先引入組件,并在components中聲明,則可以用cityPhone此組件了。

import cityPhone from "@/components/cityPhone.vue"
? ? export default {
? ? ? ? components: {
? ? ? ? ? ? cityPhone
? ? ? ? },
<script>
?? ?import cityPhone from "@/components/cityPhone.vue"
?? ?export default {
?? ??? ?components: {
?? ??? ??? ?cityPhone
?? ??? ?},
? ? },
?? ?methods: {
? ? ? ? ?? ?cityList: function() {
?? ??? ??? ??? ?this.$refs.phonePop.open()
?? ??? ??? ?}
? ? }
</scripty>

2.頁面中使用此組件

<template> 
         <view>
                <view @click="cityList()" style="padding:0;margin:0;background-color: #FFFFFF;"
                    class="member-benefits-1">
                    地市列表
                </view>
         <!--城市選擇彈窗 -->
                <cityPhone  ref="phonePop"></cityPhone>
        </view>
</template>

3.展示pop。則點(diǎn)擊地市列表,觸發(fā) cityList方法。此方法打開pop。

this.$refs.phonePop.open()

phonePop是上面2布局中cityPhone組件中,ref后面跟的名稱。

this.$refs.phonePop.open() ?//此open方法實(shí)際上是調(diào)用的。組件中的open方法,即下圖方法。
open() {
? ? ? ? ? ? ? ? //cityPhonePop是上面布局定義的uni-pop 的ref后面的名稱,即pop名 this.$refs.cityPhonePop.open()則打開pop展示。
?? ??? ??? ??? ?this.$refs.cityPhonePop.open()
?? ??? ??? ?},

三、pop組件,擴(kuò)展詳情說明

1.pop位置,可以布局中設(shè)置type,同時(shí)可以打開pop的時(shí)候參數(shù)中傳入位置。

 // 通過組件定義的ref調(diào)用uni-popup方法 ,如果傳入?yún)?shù) ,type 屬性將失效 ,僅支持 ['top','left','bottom','right','center']
 this.$refs.popup.open('top')

2. 設(shè)置主窗口背景色

大多數(shù)場(chǎng)景下,并不需要設(shè)置 background-color 屬性,

而也有特例,需要我們主動(dòng)去設(shè)置背景色,例如 type = 'bottom' 的時(shí)候 ,在異型屏中遇到了底部安全區(qū)問題(如 iphone 11),因?yàn)?uni-popup的主要內(nèi)容避開了安全區(qū)(設(shè)置safe-area:true),導(dǎo)致底部的顏色我們無法自定義,這時(shí)候使用 background-color 就可以解決這個(gè)問題。

<button @click="open">打開彈窗</button>
<uni-popup ref="popup" type="bottom" background-color="#fff">底部彈出 Popup</uni-popup>

3.禁用打開動(dòng)畫

在某些場(chǎng)景 ,可能不希望彈層有動(dòng)畫效果 ,只需要將 animation 屬性設(shè)置為 false 即可以關(guān)閉動(dòng)畫。

<button @click="open">打開彈窗</button>
<uni-popup ref="popup" type="center" :animation="false">中間彈出 Popup</uni-popup>

4.禁用點(diǎn)擊遮罩關(guān)閉

默認(rèn)情況下,點(diǎn)擊遮罩會(huì)自動(dòng)關(guān)閉uni-popup,如不想點(diǎn)擊關(guān)閉,只需將mask-click設(shè)置為false,這時(shí)候要關(guān)閉uni-popup,只能手動(dòng)調(diào)用 close 方法。

<uni-popup ref="popup" :mask-click="false">
    <text>Popup</text>
    <button @click="close">關(guān)閉</button>
</uni-popup>

到此這篇關(guān)于uniapp中uni-popup的具體使用的文章就介紹到這了,更多相關(guān)uniapp uni-popup內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:

相關(guān)文章

最新評(píng)論