头部胶囊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>
相关推荐
AKclown5 分钟前
Vibe coding(AI编程一网打尽)
前端·react.js
埋塘小王子5 分钟前
React项目白屏兜底神器?ErrorBounary你了解吗?
前端
却尘12 分钟前
一个 ERR_SSL_PROTOCOL_ERROR 让我们排查了三层问题,最后发现根本不是 SSL 的锅
前端·后端·网络协议
用户830407130570113 分钟前
如何处理axios请求中post请求的坑
前端
行走在顶尖14 分钟前
vue3项目搭建基础
前端
sudo_明天上线15 分钟前
React 核心深度解析:调度、协调与提交的闭环全解
前端
广州华水科技21 分钟前
单北斗GNSS在变形监测中的应用与发展新趋势
前端
宁雨桥26 分钟前
详解Web服务部署:IP+端口 vs IP+端口+目录 实战指南
前端·网络协议·tcp/ip
chengbo_eva33 分钟前
大前端全栈实践-基于nodejs实现服务端内核引擎
前端
一颗奇趣蛋37 分钟前
哨兵模式-无限滚动
前端