头部胶囊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>
相关推荐
小赖同学啊8 分钟前
光伏园区3d系统管理
前端·javascript·3d
木叶丸14 分钟前
编程开发中,那些你必须掌握的基本概念
前端·数据结构·编程语言
前端进阶者15 分钟前
js通知提醒
前端·javascript
拖孩21 分钟前
微信群太多,管理麻烦?那试试接入AI助手吧~
前端·后端·微信
快起来别睡了28 分钟前
看完你就知道JavaScript 中的对象创建与继承方式原来这么简单?!
javascript
乌兰麦朵38 分钟前
Vue吹的颅内高潮,全靠选择性失明和 .value 的PUA!
前端·vue.js
Goodbaibaibai38 分钟前
创建一个简洁的Vue3 + TypeScript + Vite + Pinia + Vue Router项目
javascript·vue.js·typescript
Code季风38 分钟前
Gin Web 层集成 Viper 配置文件和 Zap 日志文件指南(下)
前端·微服务·架构·go·gin
蓝倾38 分钟前
如何使用API接口实现淘宝商品上下架监控?
前端·后端·api
舂春儿40 分钟前
如何快速统计项目代码行数
前端·后端