头部胶囊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>
相关推荐
freewlt14 分钟前
前端性能优化实战:从 Lighthouse 分数到用户体验的全面升级
前端·性能优化·ux
小小亮0121 分钟前
Next.js基础
开发语言·前端·javascript
华洛28 分钟前
我用AI做了一个48秒的真人精品漫剧,不难也不贵
前端·javascript·后端
Amumu121381 小时前
Js:正则表达式(二)
开发语言·javascript·正则表达式
Novlan11 小时前
我把 Claude Code 里的隐藏彩蛋提取出来了——零依赖的 ASCII 虚拟宠物系统
前端
Sgf2271 小时前
ES8(ES2017)新特性完整指南
开发语言·javascript·ecmascript
IAUTOMOBILE2 小时前
Python 流程控制与函数定义:从调试现场到工程实践
java·前端·python
好大哥呀2 小时前
C++ Web 编程
开发语言·前端·c++
爱学习的小仙女!3 小时前
面试题 前端(一)DOCTYPE作用 标准模式与混杂模式区分
前端·前端面试题
小小小小宇3 小时前
前端转后端基础- 变量和类型
前端