uniapp在pages.json中配置原生右上角图标

本文介绍了如何在uniapp中通过pages.json配置原生右上角图标,并展示了一个示例,展示了在页面中添加按钮并触发相应事件的实现方式,包括导航栏的点击事件处理和弹出界面的样式设计。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

"app-plus": {
					"titleNView": {
						"backgroundImage": "./static/system/bar.png",
						"type": "default",
						"buttons": [{
							"fontSrc": "/static/iconfont1.ttf",
							"text": "\ue600",
							"fontSize": "25",
							"color": "#08BBC5",
							"float": "right",
							"width": "40px",
							"background": "rgba(0,0,0,0)"
						}]
					}
				}

页面部分:
        <!-- 导航栏添加按钮弹出界面 -->
        <view ref="modal" @click.stop class="arrivalNavigation" v-if="showAddButton">
            <view class="d4"></view>
            <view class="sideNavigation">
                <view :class="{'noauth':$utils.getNoAuth(this.getKey(),'')}" class="ul" @click="addBoss()">
                    <u-icon color="#333333" name="plus"></u-icon><text class="item">&nbsp;&nbsp;加老板</text>
                    <view class="liBottomBorder"></view>
                </view>
                <view :class="{'noauth':$utils.getNoAuth(this.getKey(),'')}" class="ul" @click="addManager()">
                    <u-icon color="#333333" name="plus"></u-icon><text class="item">&nbsp;&nbsp;加管理</text>
                    <view class="liBottomBorder"></view>
                </view>
                <view class="liBottomBorder"></view>
                <view :class="{'noauth':$utils.getNoAuth(this.getKey(),'00050001')}" class="ul" @click="addSquad()">
                    <u-icon color="#333333" name="plus"></u-icon><text class="item">&nbsp;&nbsp;加班组</text>
                    <view class="liBottomBorder"></view>
                </view>
                <view class="liBottomBorder"></view>
                <view :class="{'noauth':$utils.getNoAuth(this.getKey(),'00050002')}" class="ul" @click="addSubcontracting()">
                    <u-icon color="#333333" name="plus"></u-icon><text class="item">&nbsp;&nbsp;加分包</text>
                    <view class="liBottomBorder"></view>
                </view>
            </view>
        </view>
        
        script部分:(与data同级)
onNavigationBarButtonTap(e) {
            const index = e.index;
            console.log(e);
            this.showEditButton = false;
            if (this.showAddButton) {
                this.showAddButton = false
            } else {
                this.showAddButton = true;
            }

        }
        
        
        css部分
        //从这里开始是弹出框的样式 不需要搜索框的 前面样式都不用加
    .arrivalNavigation {
        width: 250rpx;
        // 
        position: fixed;
        right: 0rpx;
        z-index: 99;
        top: 0rpx;
        /* #ifdef H5 */
        margin-top: 88rpx;

        /* #endif */
        .sideNavigation {
            width: 248rpx;
            background-color: #ffffff;
            font-size: $uni-font-size-lg;
            color: $title-color;
            border-radius: 10rpx;
            text-align: center;

            .ul {
                display: flex;
                flex-direction: row;
                align-items: center;
                justify-content: center;
                position: relative;
            }

            .item {
                height: 95rpx;
                text-align: center;
                line-height: 95rpx;
                font-size: 28rpx;
            }

            .liBottomBorder {
                position: absolute;
                bottom: 0;
                right: 0;
                left: 0;
                height: 2rpx;
                -webkit-transform: scaleY(0.5);
                transform: scaleY(0.5);
                background-color: #F2F2F2;
            }
        }

        .d4 {
            // position: absolute;
            //  left: 140rpx;
            width: 0;
            height: 0;
            margin-left: 180rpx;
            margin-top: -10rpx;
            border-width: 10rpx;
            border-style: solid;
            border-color: transparent #ffffff transparent transparent;
            transform: rotate(90deg);
            /*顺时针旋转90°*/

        }
    }

    .card-row {
        display: flex;
        padding: 20rpx 30rpx;
        flex-direction: row;
        align-items: center;

        .card-row-item {
            margin-left: 30rpx;
            flex: 1;
        }
    }

### 实现 UniApp 标题栏右上角添加搜索图标或搜索框 #### 使用 `uni-icons` 图标并绑定点击事件 为了在标题栏的右上角添加一个可点击的搜索图标,可以通过自定义导航栏来实现这一需求。具体来说,在页面中引入 `uni-icons` 组件,并设置其属性以显示所需的图标。 ```html <template> <view class="custom-nav"> <!-- 自定义导航栏 --> <uni-status-bar></uni-status-bar> <!-- 占位状态栏高度 --> <view class="nav-content"> <text class="title">页面名称</text> <uni-icons type="search" size="22" color="#007AFF" @click="handleSearchClick"></uni-icons> </view> </view> <!-- 页面其他内容 --> </template> <script> export default { methods: { handleSearchClick() { console.log('搜索按钮被点击'); // 执行搜索逻辑或其他操作 } } } </script> <style scoped> .custom-nav { display: flex; align-items: center; justify-content: space-between; padding: 0 15px; height: 44px; /* 导航栏高度 */ } .nav-content { display: flex; align-items: center; justify-content: space-between; width: 100%; } .title { font-size: 18px; font-weight: bold; } /* 针对H5平台调整样式 */ /* #ifdef H5 */ .arrivalNavigation { margin-top: 88rpx; } /* #endif */ </style> ``` 上述代码展示了如何创建带有搜索图标的自定义导航栏[^1]。通过这种方式可以在不同平台上灵活控制布局和交互行为。 #### 在 pages.json配置原生右上角图标 如果希望更简单地实现在标题栏右上角放置固定的功能入口而不需要额外编写模板结构,则可以直接利用 `pages.json` 文件中的路径配置选项来进行设定: ```json { "path": "pages/index/index", "style": { "navigationBarTitleText": "首页", "navigationStyle": "default", "rightWindowButtons": [ { "type": "icon", "text": "search" } ] } } ``` 这段 JSON 片段说明了怎样快速指定某个特定页面上的默认导航条目以及关联的动作按钮[^2]。注意这里的 `"text"` 字段用于指明要使用的图标名,需参照官方文档获取支持的具体值列表。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值