头部胶囊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>
相关推荐
WindrunnerMax4 分钟前
基于 Markdown-It 的无序列表折叠插件
前端·javascript·github
剑神一笑7 分钟前
CSS Loading 动画生成器
前端·css
神三元14 分钟前
最近半年,我做了个 AI-Native 的 Agent 从零到进阶教程
前端·javascript·面试
XiYang-DING28 分钟前
jQuery
前端·javascript·jquery
Morwit28 分钟前
【力扣hot100】 221. 最大正方形
前端·算法·leetcode
明月_清风39 分钟前
关于node 模块化的现状与未来
前端·node.js
老王以为1 小时前
从源码到架构:React useActionState 深度剖析
前端·javascript·react.js
前端超有趣1 小时前
详解JavaScript中encodeURIComponent和decodeURIComponent的使用(附实战场景)
前端·javascript
XinZong1 小时前
业余抱团搞副业:基于OpenClaw做了一款AI社交虾聊,产品做完了,求运营思路
javascript
萧曵 丶1 小时前
Vue3组件通信全方案
前端·javascript·vue.js·typescript·vue3