废话不多说,直接上代码

import { ScrollView } from "@tarojs/components";
import Taro, { useReady } from "@tarojs/taro";
 
const [scrollHeight, setScrollHeight] = useState('84vh');
 
useReady(() => {
  // 设置ScrollView的动态高度
  Taro.nextTick(() => {
    Taro.getSystemInfo({
      success: (res) => {
        const query = wx.createSelectorQuery();
        query.select("#scrollview").boundingClientRect();
        query.exec((resData) => {
          console.log('resres', res)
          console.log('resData', resData)
          if (resData && resData.length) {
            setScrollHeight(res.screenHeight - resData[0].top + "px")
          }
        });
      },
    });
  });
});
 
<ScrollView
  style={{ height: scrollHeight }}
  id="scrollview"
  scrollY
  scrollWithAnimation
  >
 
 
</ScrollView>

浪迹天涯小king
15 声望1 粉丝