当前位置: 首页 > web >正文

uniapp自定义导航栏搭配插槽

在这里插入图片描述

      <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
// 返回上级页面
const back = () => {uni.navigateBack({delta: 1});
};
<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

在这里插入图片描述

      <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>
$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;
}
http://www.xdnf.cn/news/5100.html

相关文章:

  • Linux的进程与线程
  • 笔记,麦克风的灵敏度
  • Jedis高版本的JedisPoolConfig没有maxActive和maxWait
  • Linux使用Docker部署安装应用
  • Papyrus字体介绍
  • 为什么消息队列系统不像数据库系统那样可以配置读写分离?
  • Docker基础入门:容器化技术详解
  • PH热榜 | 2025-05-09
  • class path resource [] cannot be resolved to absolute file path
  • powershell_bypass.cna 插件(适配 Cobalt Strike 4.0 的免费版本下载地址)
  • FreeRTOS菜鸟入门(十四)·事件
  • Prometheus生产实战全流程详解(存储/负载/调度篇)
  • 认识拦截器
  • 如何获取NumPy数组中前N个最大值的索引
  • Qt6.x检查网络是否在线(与Qt 5.x不同)
  • 有关SOA和SpringCloud的区别
  • 软件设计师教程——第一章 计算机系统知识(下)
  • 数据库插入数据时自动生成
  • Python开发后端InfluxDB数据库测试接口
  • Python 数据分析与可视化:开启数据洞察之旅(5/10)
  • T-SQL在SQL Server中判断表、字段、索引、视图、触发器、Synonym等是否存在
  • 详解 c++17 重载类 overload的每一条语句,附实例.
  • Dify之八添加各种在线大模型
  • P1020 [NOIP 1999 提高组] 导弹拦截
  • Java——多态
  • 热力图是什么?三分钟学会热力图数据分析怎么做!
  • Dify MCP实战 - 邮件发送
  • 【动态导通电阻】p-GaN HEMTs正向和反向导通下的动态导通电阻
  • MySQL数据库故障排查与解决方案
  • VMware中ubuntu虚拟机基本配置