头部胶囊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>
相关推荐
大雨还洅下12 分钟前
前端JS: 虚拟dom是什么? 原理? 优缺点?
javascript
唐叔在学习13 分钟前
[前端特效] 左滑显示按钮的实现介绍
前端·javascript
用户52822903018037 分钟前
【学习笔记】ECMAScript 词法环境全解析
前端
青青家的小灰灰39 分钟前
React 架构进阶:自定义 Hooks 的高级设计模式与最佳实践
前端·react.js·前端框架
Angelial1 小时前
Vite 性能瓶颈排查标准流程
前端
不要秃头啊1 小时前
别再谈提效了:AI 时代的开发范式本质变了
前端·后端·程序员
青青家的小灰灰1 小时前
深入理解事件循环:异步编程的基石
前端·javascript·面试
用泥种荷花1 小时前
【LangChain.js学习】 向量数据库(内存/持久化)
前端
simon_luv_pho1 小时前
一行代码把网页变成 AI Agent?
前端
兆子龙1 小时前
模块联邦(Module Federation)详解:从概念到手把手 Demo
前端·架构