uni-app subNVue 原生子窗體簡(jiǎn)單使用案例(app提交按鈕)

因?yàn)樵牡貓Dmap、video等層級(jí)較高,其他的組件無法正常顯示,所以使用彈出層用到原生子窗體subNvue
效果如下:


image.png
image.png

用法:
1、在需要使用的頁面(addSamplePage)下新建subNvue文件夾,然后在里面建立相應(yīng)的文件nvue


image.png

2、在pages.json中定義,把樣式什么的直接寫在需要引用的頁面中,例如寫在index頁面里

{
            "path": "pages/addSamplePage/addSamplePage",
            "style": {
                "navigationBarTitleText": "樣品檢測(cè)新增頁",
                "app-plus": {
                    "subNVues": [
                        {
                            "id": "video_mask",
                            "path": "pages/addSamplePage/subnvue/top",
                            "style": {
                                "position": "absolute",
                                "bottom": "0",
                                "left": "0",
                                "width": "100%",
                                "height": "90px",
                                "background": "transparent"
                            }
                        }
                    ]
                }

            }
        }

3.top.nvue頁面

<template>
    <div class="wrapper">
        <div class="list">
            <text class="text" @click="submit('0')">保存</text>
            <text class="text" @click="submit('1')">提交</text>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
            
            }
        },
        created() {

        },
        beforeDestroy() {
        },
        methods: {
            submit(e) {
                uni.$emit('drawer-page', e);
            },

        }
    }
</script>

<style>
    .wrapper {
        position: relative;
        flex: 1;
        justify-content: center;
        align-items: center;
        background-color: #fff;
        border-color: #eee;
        border-style: solid;
        border-width: 4px;

    }


    .list {
        position: absolute;
        width: 640rpx;
        height: 90px;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;

    }

    .text {
        height: 50px;
        color: #fff;
        background-color: #192c7c;
        width: 275rpx;
        text-align: center;
        line-height: 50px;
        border-radius: 25px;
        font-size: 30upx;
    }
</style>

4.在addSamplePage.vue頁面中使用方法

<script>
    export default {
        data() {
            return {};
        },

        onLoad() {
            // #ifdef APP-PLUS
            this.playVideo()
            uni.$on('drawer-page', (data) => {
                uni.showToast({
                    title: '點(diǎn)擊了第' + data + '項(xiàng)',
                    icon: "none"
                });
            })
            // #endif
        },
        onUnload() {
            uni.$off('drawer-page')
        },
        methods: {
            playVideo() {
                let subNVue = uni.getSubNVueById('video_mask')
                subNVue.show()
            }
        }
    }
</script>

需要注意的是nvue文件中很多css都不支持,文字必須寫在text內(nèi)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容