uniapp自定义导航栏搭配插槽

html 复制代码
      <uni-nav-bar dark :fixed="true" shadow background-color="#007AFF" left-icon="left" left-text="返回" @clickLeft="back">
        <view class="nav-bar-title">{{ navBarTitle }}</view>
        <block v-slot:right>
          <uni-icons type="search" size="24" color="#fff" @click="toSearch" />
          <uni-icons type="cart" size="24" color="#fff" @click="toCart" />
        </block>
      </uni-nav-bar>

注意点:

  1. 使用插槽需要用"block"标签包裹
  2. 具名插槽的写法:
    vue2: slot="left"
    vue3: v-slot:left 或者 #left
js 复制代码
// 返回上级页面
const back = () => {
  uni.navigateBack({
    delta: 1
  });
};
css 复制代码
<style lang="scss" scoped>
.pd {
  margin: 30rpx 0;
  padding: 0 30rpx;
}

.nav-bar-title {
  font-size: 36rpx;
  color: #fff;
}

::v-deep .uni-navbar__header-container {
  justify-content: center;
  align-items: center;
}

::v-deep .uni-navbar__header-btns-right {
  justify-content: space-around;
}
</style>

效果2

html 复制代码
      <uni-nav-bar left-icon="left" shadow background-color="#007AFF" @clickLeft="back">
        <view class="input-view">
          <uni-icons class="input-uni-icon" type="search" size="18" color="#999" />
          <input confirm-type="search" v-model="keyWords" maxlength="12" class="nav-bar-input" type="text" placeholder="Vue" @confirm="handelSearch(keywords)" />
        </view>
        <block v-slot:right>
          <view class="city" @click="handelSearch(keyWords)">搜索</view>
        </block>
      </uni-nav-bar>
css 复制代码
$nav-height: 60rpx;

.title-font {
  height: 50px;
  font-size: 14px;
  font-weight: 700;
  color: #636363;
}

.input-view {
  display: flex;
  flex-direction: row;
  flex: 1;
  background-color: #f8f8f8;
  height: $nav-height;
  line-height: $nav-height;
  border-radius: 30rpx;
  padding: 0 30rpx;
  flex-wrap: nowrap;
  margin: 14rpx 0;
}

.nav-bar-input {
  height: $nav-height;
  line-height: $nav-height;
  /* #ifdef APP-PLUS-NVUE */
  width: 370rpx;
  /* #endif */
  padding: 0 5px;
  font-size: 12px;
  background-color: #f8f8f8;
}

::v-deep .uni-navbar__header-btns-left {
width: 30px !important;
}
::v-deep .uni-navbar__header-btns-right {
  justify-content: center;
}
相关推荐
一份执念15 小时前
uni-app项目 (vue+vite + uni-UI)中引入umd格式JS文件,微信小程序中导入报错处理方案
前端·uni-app·echarts
PedroQue9921 小时前
V1.6.1性能优化:高频路径提速与代码精简
前端·uni-app
夏碧笔3 天前
uni-app跨端地图实战:用第三方LBS替代微信平台收费服务
uni-app
用户6990304848758 天前
try catch使用场景 处理同步代码错误兼容用的
javascript·uni-app
ITKEY_8 天前
uniapp微信开发者工具 更改AppID失败 touristappid
uni-app
Geek_Vison8 天前
APP瘦身实战:从80MB+砍到15MB——基于小程序容器技术剥离APP非核心业务的实践分享
小程序·uni-app·mpaas
CHB9 天前
HDC2026 演讲实录|AI 驱动的跨端进化:利用 uni-agent 快速构建高性能鸿蒙应用
uni-app·harmonyos
2501_915918419 天前
iOS App性能测试工具的实现方法与优化循环指南
android·ios·小程序·https·uni-app·iphone·webview
斯内普吖9 天前
(开源)高校素拓分管理系统小程序实战指南 基于 Java + SpringBoot + uni-app + Vue + MySQL
java·spring boot·mysql·小程序·uni-app·开源
海阔天空66889 天前
uniapp开启调试模式
uni-app·uniapp开启调试模式