头部胶囊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>
相关推荐
卡西里弗斯奥几秒前
【Tomcat】部署Web服务器之Tomcat
服务器·前端·tomcat
Sheldon一蓑烟雨任平生17 分钟前
Sass 星空(Sass + keyframes 实现星空动画)
前端·css·vue3·sass·keyframes
⑩-24 分钟前
VUE3学习
前端·javascript·vue.js
Mr Xu_29 分钟前
Vue 3 中使用 mitt 实现组件间通信的实践与解析
前端·javascript·vue.js
呃m38 分钟前
更好地使用Google Chrome
前端·chrome
巧克力芋泥包38 分钟前
Vue3 详情页跨页循环(上一条,下一条)导航功能实现
前端·javascript·vue.js
摘星编程1 小时前
React Native + OpenHarmony:BottomSheet联动效果实现
javascript·react native·react.js
前端之虎陈随易1 小时前
前端通用插件开发工具unplugin v3.0.0发布
前端·typescript
Ashley_Amanda1 小时前
SAP调用Web Service全流程详解
java·前端·数据库
Dreamy smile1 小时前
css :nth-child() 完全用法指南
前端·css