壁纸小程序Vue3(自定义头部组件)

1.自定义头部

coustom-nav

复制代码
<view class="layout">
    <view class="navbar">
        <view class="statusBar"></view>
        <view class="titleBar">
          <view class="title">标题</view>
            <view class="search">
                <uni-icons class="icon" type="search" color="#888" size="18"></uni-icons>
                <text class="text">搜索</text>
            </view>
        </view>
    </view> 

.layout{
  .navbar{
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 999;
    background:
    // linear-gradient(to bottom,rgba(0,0,0,0) 50%,#fff 100%),
    linear-gradient(to bottom,rgba(0,0,0,0) , #fff  400rpx),
    linear-gradient(to right,#beecd8 20%,#F4E2D8);
    .statusBar {}
    .titleBar{
      display: flex;
      align-items: center;
      padding: 0 30rpx;
      // height: 100rpx;
      .title{
        font-size: 22px;
        font-weight: 700;
        color: $text-font-color-1;
      }
      .search{
         width: 220rpx;
         height: 50rpx;
         border-radius: 60rpx;
         background: rgba(255, 255, 255, 0.4);
         border: 1px solid #fff;
         margin-left: 30rpx;
         color: #999;
         font-size: 28rpx;
         display: flex;
         align-items: center;
         .text{
           padding-left: 10rpx;
         }
         .icon{
           margin-left: 5rpx;
         }
         
       }
     	  
    }
  }

1)状态栏

<view class="statusBar" :style="{height:statusBarHeight+'px'}"></view>

H5中为0

<view class="titleBar" :style="{height:titleBarHeight+'px'}">

获取胶囊位置
<view class="fill" :style="{height:statusBarHeight+titleBarHeight+'px'}">

</view>

填充区域,让轮播图展示全

<script setup>

import { ref } from 'vue'

//状态栏

let SYSTEM_INFO = uni.getSystemInfoSync();

let statusBarHeight = ref(SYSTEM_INFO.statusBarHeight)

// 获取胶囊按钮信息

let {top,height} = uni.getMenuButtonBoundingClientRect();

let titleBarHeight = ref(height + (top - statusBarHeight.value)*2)

</script>

2.封装组件

上面的做法在H5中会报错,所以创建一个utils.js

const SYSTEM_INFO = uni.getSystemInfoSync();

export const getStatusBarHeight = () => SYSTEM_INFO.statusBarHeight || 0;

export const getTitleBarHeight = ()=>{

if(uni.getMenuButtonBoundingClientRect){

let {top,height} = uni.getMenuButtonBoundingClientRect();

return height + (top - getStatusBarHeight())*2

}else{

return 40;

}

}

export const getNavBarHeight = ()=> getStatusBarHeight() + getTitleBarHeight();
<script setup>

import { ref } from 'vue'

import { getStatusBarHeight, getTitleBarHeight, getNavBarHeight } from '@/utils/system.js'

</script>

3.动态定义标题

<script setup>

import { ref } from 'vue'

import { getStatusBarHeight, getTitleBarHeight, getNavBarHeight } from '@/utils/system.js'
defineProps({

title:{

type:String,

default:"壁纸"

}

})

</script>
<custom-nav-bar title="分类"></custom-nav-bar>

preview.vue

<view class="goBack" :style="{top:getStatusBarHeight()+'px'}" @click="goBack">


//返回上一页

const goBack = ()=>{

uni.navigateBack()

}

4.点击公告进行跳转

notice.vue

复制代码
<template>
  <view class="noticeLayout">
      <view class="title">
          <view class="tag">
            <uni-tag text="置顶" type="error" inverted></uni-tag>
          </view>
          <view class="font">这个区域填写标题</view>
      </view>
      <view class="info">
        <view class="item">君泺</view>
        <view class="item">
          <uni-dateformat :date="Date.now()" format="yyyy-MM-dd hh:mm:ss"></uni-dateformat>
        </view>
      
      </view>
      
      <view class="content">
        内容区域
      </view>
      
      <view class="count">
        阅读 5588
      </view>
      
    </view>
</template>

<script>
  export default {
    data() {
      return {
        
      }
    },
    methods: {
      
    }
  }
</script>

<style lang="scss">
.noticeLayout{
	padding:30rpx;
		.title{
			font-size: 40rpx;
			color:#111;
			line-height: 1.6em;
			padding-bottom:30rpx;
			display: flex;
			.tag{
				transform: scale(0.8);
				transform-origin: left center;
				flex-shrink: 0;	
			}
			.font{
				padding-left:6rpx;
			}
		}
		.info{
			display: flex;
			align-items: center;
			color:#999;
			font-size: 28rpx;
			.item{
				padding-right: 20rpx;
			}
		}
		.content{
			padding:50rpx 0;
		}
		.count{
			color:#999;
			font-size: 28rpx;
		}
}
</style>
相关推荐
像我这样帅的人丶你还18 分钟前
从交稿到甩锅预防:AI 前端流水线
前端·ai编程
想想弹幕会怎么做19 分钟前
如何构建一颗可交互的ui树?
前端
程序员陆业聪24 分钟前
我见过的最反直觉的 Android 架构问题:UseCase 越多,项目越烂
前端
Arya_aa30 分钟前
网络:前端向后端发送网络请求渲染在页面上,将EasyMock中的信息用前端vue框架编写代码,最终展示在浏览器
前端·vue.js
LlNingyu31 分钟前
文艺复兴,什么是CSRF,常见形式(一)
前端·安全·web安全·csrf
晓131334 分钟前
React篇——第三章 状态管理之 Redux 篇
前端·javascript·react.js
子兮曰39 分钟前
🚀24k Star 的 Pretext 为何突然爆火:它不是排版库,而是在重写 Web 文本测量
前端·javascript·github
@大迁世界43 分钟前
11.在 React.js 中,state 与 props 的差异体现在哪里?
前端·javascript·react.js·前端框架·ecmascript
Giant1001 小时前
🔥前端跨域封神解法:Vite Proxy + Express CORS,一篇搞定所有跨域坑!
前端·javascript·面试
土土哥V_araolin1 小时前
多语言推三返一商城系统开发指南
小程序·零售