头部胶囊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>
相关推荐
sibylyue2 分钟前
Typescritpt、ES6
前端·javascript·vue.js
用户3076752811273 分钟前
《拒绝卡顿:深入解析 AI 流式 Markdown 的高性能渲染架构》
前端·javascript
Mertens18745 分钟前
Zero-Doc:极简的 Spec Coding 落地指南
前端·javascript·ai编程
毛骗导演5 分钟前
万字解析 OpenClaw 源码架构-跨平台应用之MacOS 应用
前端·架构
ZengLiangYi6 分钟前
用 1300 行原生 JS 做了一个 Chrome DevTools 扩展,让前后端不再为接口报错截图扯皮
前端·javascript
A_Qyp6 分钟前
JeechBoot前端表格内操作设置下拉
前端·javascript
YimWu7 分钟前
面试官:OpenCode Agent 代理机制了解吗?
前端·agent·ai编程
小小程序员mono11 分钟前
JS 与 Vue Router 导航方式对比
开发语言·javascript·vue.js
IT星宿11 分钟前
smart-unit:一个优雅的 JavaScript 单位转换库,告别繁琐的依赖管理
前端·javascript·typescript
Sgf22736 分钟前
如何阅读 React 源码:系统化学习指南
前端·react.js·前端框架