头部胶囊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>
相关推荐
Q***l6871 分钟前
Vue增强现实案例
前端·vue.js·ar
十里-11 分钟前
前端监控1-数据上报
前端·安全
初学者,亦行者15 分钟前
DevUI微前端集成实战解析
前端·typescript
han_18 分钟前
前端高频面试题之CSS篇(一)
前端·css·面试
小小测试开发18 分钟前
JMeter XPath2 Extractor用法全解析:精准提取XML/HTML响应数据
xml·jmeter·html
b***748826 分钟前
Vue开源
前端·javascript·vue.js
不知更鸟33 分钟前
前端报错:快速解决Django接口404问题
前端·python·django
D***t1311 小时前
React图像处理案例
前端
万少2 小时前
我是如何使用 Trae IDE 完成《流碧卡片》项目的完整记录
前端·后端·ai编程
9***Y482 小时前
前端微服务
前端·微服务·架构