头部胶囊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>
相关推荐
西西学代码10 分钟前
Flutter---异步编程
开发语言·前端·javascript
拉不动的猪11 分钟前
CSS 像素≠物理像素:0.5px 效果的核心密码是什么?
前端·css·面试
前端市界17 分钟前
Copilot新模型GPT-5.1太强了!自动生成完美Axios封装,同事都看傻了
前端·前端框架·github
米欧18 分钟前
取消当前正在进行的所有接口请求
前端·javascript·axios
浪里行舟22 分钟前
告别“拼接”,迈入“原生”:文心5.0如何用「原生全模态」重塑AI天花板?
前端·javascript·后端
OpenTiny社区23 分钟前
救命!这个低代码工具太香了 ——TinyEngine 物料自动导入上手
前端·低代码·github
努力学前端Hang24 分钟前
移动端跨平台开发深度解析:UniApp、Taro、Flutter 与 React Native 对比
前端·javascript·react native·react.js
前端九哥35 分钟前
🚫循环里写return,浏览器当场沉默!
前端·javascript
亲爱的马哥42 分钟前
填鸭表单!开箱即用的开源问卷调查系统!
java·前端·低代码·产品经理
米诺zuo1 小时前
nextjs文件路由、路由组
前端·next.js