头部胶囊input框与胶囊对其

javascript 复制代码
<template>
	<view class="box">
		<input :style="{ width: withs, top:tops,height: hights}" type="text" value="" />
	</view>
</template>

<script>
	export default {

		data() {
			return {
				tops: '',
				withs: '',
				hights: ''
			}
		},


		methods: {},
		onLoad() {
			const res = uni.getMenuButtonBoundingClientRect()
			this.hights = res.height + 'px'
			this.withs = res.left * 0.6 + 'px'
			this.tops = res.top + 'px'
			console.log(this.tops, `kkk`)
		},
	}
</script>

<style lang="scss">
	.box {

		position: relative;

		input {
			border-radius: 20px;
			border: 1px solid black;
			position: absolute;
		}
	}
</style>

vue3写法

javascript 复制代码
<template>
	<view>
		<input class="input" :style="{width:width,height:height,top:top}" type="text">
		<u-icon name="search" size="20"></u-icon>

	</view>
</template>

<script setup>
	import {
		ref
	} from "vue"
	import {
		onLoad
	} from "@dcloudio/uni-app"
	const height = ref('')
	const width = ref('')
	const top = ref('')

	onLoad(async () => {
		const res = uni.getMenuButtonBoundingClientRect()
		console.log(res);
		top.value = res.top + 'px'
		width.value = res.left * 0.8 + 'px'
		height.value = res.height + 'px'

	})
</script>

<style>
	.input {
		border: 1rpx solid black;
		box-sizing: border-box;
		border-radius: 40rpx;
		position: absolute;
		left: 50rpx;

	}
</style>
相关推荐
GalenZhang8888 分钟前
OpenClaw (2026.4.x 至 2026.5.12) 升级问题及解决
前端·chrome·openclaw
Ww.xh16 分钟前
鸿蒙Web组件中Hash路由传登录态方案
前端·哈希算法·harmonyos
LCG元1 小时前
STM32实战:基于STM32F103的智慧教室环境监控系统(CO₂+光照+人数统计)
前端·stm32·嵌入式硬件
yqcoder1 小时前
Vue 的心脏:深度解析 Vue 2 vs Vue 3 响应式机制
前端·javascript·vue.js
东方小月1 小时前
Claude Code Skill 完全指南:一个 markdown 文件,就是一个专家分身
前端·后端
DianSan_ERP2 小时前
抖店订单接口中消费者信息加密解密机制与安全履约全解析
前端·网络·数据库·后端·安全·团队开发·运维开发
PBitW2 小时前
一个skill,让项目管理和写绩效变得简单!
前端·trae
Dxy12393102162 小时前
CSS中的filter属性详解
前端·css
Vincent_czr2 小时前
iOS中常常遇到后端返回JSON出现null值问题
前端
问心无愧05132 小时前
ctf show web入门90
前端·笔记