头部胶囊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>
相关推荐
ricardo197336 分钟前
手写一个虚拟列表,万级数据滚动 FPS 稳定 60 帧
前端
小KK_39 分钟前
新手必看:一篇文章带你搞懂JavaScript作用域
前端
万邦科技Lafite39 分钟前
如何通过 item_search_img API 接口获取淘宝商品信息
java·前端·数据库
Jx65742 分钟前
初学者视角下的JavaScript作用域理解
javascript
杰建云1671 小时前
为什么要做商城小程序
html
AlbertZein1 小时前
干了三年全栈才悟到:TS + React 这套组合,真不是堆技术堆出来的
前端
化为五月1 小时前
我把 Hermes 接进了飞书,结果卡在“能发消息但就是不回”
前端
ClouGence1 小时前
豆包收费之后,我找到了更好用的 AI 工具
前端·人工智能·后端·ai·ai编程·ai写作
aircrushin1 小时前
音乐节结束前,拿手机📱搓了一个工具
前端·后端
廖松洋(Alina)1 小时前
07答案比对与反馈UI-鸿蒙PC端Electron开发
javascript·ui·华为·electron·开源·harmonyos·鸿蒙