赞
踩
uniapp + vue3.2 开发小程序 用ref获取DOM元素一直为null
尝试了以下几种方案:
有人遇到同款问题并已解决的看到捞一下我…
<template> <view class="index"> <view class="index_navbar" ref="navBar"> huuhu </view> </view> </template> <script setup> import { ref, onMounted, reactive, nextTick } from "vue"; const navBar = ref(null) onMounted(() => { getMenuBtnClient(); }) function getMenuBtnClient() { const btn_client = wx.getMenuButtonBoundingClientRect() console.log(btn_client) console.log(navBar.value) // 为null // navbar.style.top = btn_client.top // navbar.style.left = btn_client.right } </script>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。