首页 > 编程语言 >uni-app vue3获取 小程序胶囊最新的方法

uni-app vue3获取 小程序胶囊最新的方法

时间:2024-09-13 13:23:31浏览次数:3  
标签:const buttonData app but height button vue3 uni top

1.第一步app.vue

<script setup>
	
	import { onLaunch } from '@dcloudio/uni-app';
	onLaunch(()=>{
		// 获取胶囊按钮的位置
		const buttonPositon = uni.getStorageSync('buttonPositon')
		if(!buttonPositon){
			const res = uni.getMenuButtonBoundingClientRect()
			console.log(res)
			uni.setStorageSync('buttonPositon',res) 
		}
		
	})
</script>
  
<style>
	/*每个页面公共css */
	view,text{
		display: block;
		font-size: 33rpx;
	}
	image{
		display: block;
	}    
	button::after{
		border: none;
	}
	button{
		padding: 0;
		margin: 0;
		line-height: inherit;
		background-color: #fff;
	}
</style>

2。第二步创建一个公用api 文件


文件里面

import { reactive } from "vue"
// 获取胶囊按钮的位置

export const buttonPosition = ()=>{
	const buttonData = reactive({
		  but_height:'0px',
		  but_top:'0px',
		  but_button:'0px' 
	})
	const {height,bottom,top} = uni.getStorageSync('buttonPositon')
	buttonData.but_height = height + 'px',
	buttonData.but_button = bottom + 'px',
	buttonData.but_top = top + 'px'
	return {
		but_height:buttonData.but_height,
		but_top:buttonData.but_top,
		but_button:buttonData.but_button
	}
}

4步引入用

 <template>
	 <!-- 顶部导航切换 -->
	<view class="menu-page">
		<view class="button-top">
			
		</view>
		<view class="menu-style">
			<text v-for="(item,index) in menu" :key="index">{{item}}</text>
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	// 胶囊按钮坐标
	import {buttonPosition} from '@/api/component-api.js'
	const {but_height,but_top,but_button} = buttonPosition()
	const menu = ref(['我的','对话','AI绘画'])
</script> 
  
<style lang="less">
	page{
		background-color: #f3f3f3;
	}
	.menu-page{
		background: linear-gradient(#fce7cc,#f3f3f3);
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		z-index: 999; 
		.button-top{
			height: v-bind('but_top');
		}
		.menu-style{
			display: flex;
			align-items: center; 
			height: v-bind('but_height');
		}
	}
</style> 

标签:const,buttonData,app,but,height,button,vue3,uni,top
From: https://blog.csdn.net/weixin_59627728/article/details/142208415

相关文章

  • VUE框架Vue3组件传送实现模态窗口切换------VUE框架
    <template><divclass="s1"><h1>我是App组件</h1><YeYe></YeYe></div></template><script>importYeYefrom"./components/YeYe.vue";exportdefault{name......
  • UniGUI的布局(结合官方自带DEMO)要点记录
    UniGUI的页面布局还是比较方便的,基本什么的排版都能搞好。但UniGUI的资料实在是太少,只能看到一些零星的资料,结合UniGUI官方自带的DEMO,本人将布局有关要点整理了一下,方便查阅,也供各位爱好者参考,不对之处,敬请指正。一、布局方式传统Delphi程序的布局方法通过将属性Align添加到......
  • 基于SpringBoot+Vue+uniapp的图书馆管理系统(源码+lw+部署文档+讲解等)
    文章目录前言详细视频演示具体实现截图技术栈后端框架SpringBoot前端框架Vue持久层框架MyBaitsPlus系统测试系统测试目的系统功能测试系统测试结论为什么选择我代码参考数据库参考源码获取前言......
  • 基于SpringBoot+Vue+uniapp的成绩管理系统(源码+lw+部署文档+讲解等)
    文章目录前言详细视频演示具体实现截图技术栈后端框架SpringBoot前端框架Vue持久层框架MyBaitsPlus系统测试系统测试目的系统功能测试系统测试结论为什么选择我代码参考数据库参考源码获取前言......
  • 基于SpringBoot+Vue+uniapp的健身房预约系统(源码+lw+部署文档+讲解等)
    文章目录前言详细视频演示具体实现截图技术栈后端框架SpringBoot前端框架Vue持久层框架MyBaitsPlus系统测试系统测试目的系统功能测试系统测试结论为什么选择我代码参考数据库参考源码获取前言......
  • uniCloud
    https://doc.dcloud.net.cn/uniCloud/什么是uniClouduniCloud推出了opendb,包含了大量的开源数据库模板,常见数据表无需自己设计uniCloud推出了JQL(JavascriptQueryLanguage),会js即可掌握数据库查询,更对联表查询、Tree查询提供了非常简便的操作封装在数据库的schema中定义两个......
  • 一个Android App最少有几个线程?实现多线程的方式有哪些?
    本文首发于公众号“AntDream”,欢迎微信搜索“AntDream”或扫描文章底部二维码关注,和我一起每天进步一点点多线程编程是Android应用开发中非常重要的一个环节,可以有效地提升应用的性能和用户体验。下面是对Android中多线程相关内容的详细介绍,包括app最少有几个线程。1.基本概念主线......
  • vue3 + vite 使用 vite-plugin-svg-icons 插件显示本地 svg 图标的方法
    1.安装vite-plugin-svg-icons插件yarnaddvite-plugin-svg-icons-D//或者npminstallvite-plugin-svg-icons-D//或者pnpminstallvite-plugin-svg-icons-D2.使用vite-plugin-svg-icons插件2.1在项目根目录查找vite.config.js,进行配置import{createS......
  • vue3在引入组件时报'has no default export'
    原文:https://blog.csdn.net/weixin_53042678/article/details/138254610这个虽然不影响程序的运行,但是有强迫症患者觉得爆红难受,报错如下: 这个解决的方法也很简单,点击Vscode左下角的设置  添加 "vetur.validation.script":false,重启Vscode即可生效  ......
  • 智能指针unique_ptr<>创建的过程
    智能指针unique_ptr<>创建的过程两种初始化方式的比较std::unique_ptr可以通过两种方式进行初始化:直接构造或者使用std::make_unique()。它们之间的区别如下:直接构造std::unique_ptr:你可以通过直接构造来创建一个unique_ptr,如下:std::unique_ptr<int>ptr(newint(42));......