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

news/2024/7/20 1:20:15 标签: 小程序, 前端, javascript

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>


http://www.niftyadmin.cn/n/5464447.html

相关文章

黑马HTMLCSS基础

黑马的笔记和资料都是提供好了的&#xff0c;这个文档非常适合回顾复习。我在黑马提供的笔记上做了一些微不足道的补充&#xff0c;以便自己复习查阅。该笔记比较重要的部分是 表单&#xff0c;http请求 第一章. HTML 与 CSS HTML 是什么&#xff1a;即 HyperText Markup lan…

01xcxjc

1.小程序基础 配置文件 组件样式 事件系统 wxml语法 生命周期 小程序API 自定义组件 分包加载 开放能力 教程通信 npm支持 2.文件和目录介绍 一个完整的小程序分为两个部分 主体文件 &#xff08;全局文件&#xff09; 放到项目的根目录下 …

【大数据存储】实验1 Hadoop伪分布式安装

实验1 Hadoop伪分布式安装 下载安装虚拟机软件Vmware&#xff0c;下载Ubuntu镜像文件&#xff0c;安装Ubuntu虚拟机 在Ubuntu系统中创建用户 已有用户prx17 更新APT,安装vim 使用vim创建并编辑一个文件 vim hello.c &#xff08;按o键进入编辑模式&#xff09; 源程序 #i…

shell实现两台服务器的文件实时同步

背景 如果要实现两台服务器的文件的热备份&#xff0c;要怎么做呢&#xff1f;使用shell脚本可以轻松实现。 分析 实现文件实时监控的命令为&#xff1a;inotifywait。 当文件有新增、修改、删除等操作时&#xff0c;这个文件监控就会触发事件&#xff0c;来通知你。 文件同…

竞赛常考的知识点大总结(七)图论

最短路 最短路问题&#xff08;Shortest Path Problem&#xff09;是图论中的一个经典问题&#xff0c;它要求在给定的图中找到两个顶点之间的最短路径。最短路问题可以是单源最短路问题&#xff08;从一个顶点到其他所有顶点的最短路径&#xff09;或所有对最短路问题&#x…

入门教程:Windows搭建C语言和EasyX开发环境

&#x1f31f; 前言 欢迎来到我的技术小宇宙&#xff01;&#x1f30c; 这里不仅是我记录技术点滴的后花园&#xff0c;也是我分享学习心得和项目经验的乐园。&#x1f4da; 无论你是技术小白还是资深大牛&#xff0c;这里总有一些内容能触动你的好奇心。&#x1f50d; 如果对你…

瑞吉外卖实战学习--10、完成新增菜品分类

完成新增菜品分类 前言1、前期准备定义实体类和实体对象 2、创建修改的接口 前言 1、前期准备 定义实体类和实体对象 package com.example.ruiji_demo.entity;import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; …

【虚幻引擎】C++ slate全流程开发教程

本套课程介绍了使用我们的虚幻C去开发我们的编辑器&#xff0c;扩展我们的编辑器&#xff0c;设置我们自定义样式&#xff0c;Slate架构设计&#xff0c;自定义我们的编辑器样式&#xff0c;从基础的Slate控件到我们的布局&#xff0c;一步步的讲解我们的的Slate基础知识&#…