头部胶囊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>
相关推荐
parade岁月1 分钟前
Tailwind CSS v4 — 当框架猜不透你的心思
前端·css
小明9134 分钟前
基于Rokid CXR-M SDK的AI饮食健康助手开发实战
前端
一枚前端小姐姐5 分钟前
低代码平台表单设计系统技术分析(实战三)
前端·vue.js·低代码
牛奶5 分钟前
ts随笔:面向对象与高级类型
前端·面试·typescript
牛奶6 分钟前
React 基础理论 & API 使用
前端·react.js·面试
大漠_w3cpluscom9 分钟前
别再死记CSS属性了!真正能让你少走半年弯路的,是这套思维
前端
兆子龙29 分钟前
用 React + Remotion 做视频:入门与 AI 驱动生成
前端·架构
SuperEugene33 分钟前
从 Vue2 到 Vue3:语法差异与迁移时最容易懵的点
前端·vue.js·面试
鼓浪屿36 分钟前
vue3:组件中,v-model的区别(新版)
前端
Leon1 小时前
新手引导 intro.js 的使用
前端·javascript·vue.js