uni-app项目中自定义搜索导航栏(三端兼容性问题处理)

说明:这里以首页

1.首先处理微信小程序端

(1)在主页面中

<!-- 搜索 -->
<!-- #ifdef MP-WEIXIN -->
<view class="header-search">
    <uni-search-bar class="uni-mt-10" radius="36" placeholder="自动显示隐藏" clearButton="auto" cancelButton="none"
        @confirm="search" bgColor="rgba(255,255,255,0.7)"/>
</view>
<!-- #endif -->
/* 搜索 */
.header-search {
    width: 100%;
    position: fixed;
    top: -10rpx;
    z-index: 2
    .search-result {
        padding-top: 10px;
        padding-bottom: 20px;
        text-align: center;
    
    .search-result-text {
        text-align: center;
        font-size: 14px;
        color: #666;
    
    .example-body {
        /* #ifndef APP-NVUE */
        display: block;
        /* #endif */
        padding: 0px;
    
    .uni-mt-10 {
        margin-top: 10px;
    
    /deep/.uni-searchbar__text-placeholder {
        color: #6d6d6d;
    
    /deep/.uniui-search {
        color: #6d6d6d !important;
    }
}

2.处理app和H5端

(1)在pages.json中配置首页

{
    "path": "pages/index/index",
    "style": {
        "navigationBarTitleText": "商城首页",
        "app-plus": {
            "titleNView": {
                "type": "transparent",
                "searchInput": {//下面是输入框样式
                    "backgroundColor": "rgba(231,231,231,.7)",
                    "borderRadius": "16px",
                    "placeholder": "请搜索宝贝名称",
                    "disabled": true,
                    "placeholderColor": "#606266"
                },
                "buttons": []
            }
        }
    }
}

(2)在首页文件中

onNavigationBarSearchInputClicked(e) {//点击跳转到搜索页面
                uni.navigateTo({
                    url: "/pages/index/search"
                })
            }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值