张延森 vor 4 Jahren
Ursprung
Commit
8e2a06e680
2 geänderte Dateien mit 21 neuen und 13 gelöschten Zeilen
  1. 10
    5
      src/layout/index.jsx
  2. 11
    8
      src/pages/shop/index.jsx

+ 10
- 5
src/layout/index.jsx Datei anzeigen

@@ -1,14 +1,19 @@
1
-import React from 'react';
1
+import React, { useRef, useEffect, useImperativeHandle } from 'react';
2 2
 import { View, ScrollView } from '@tarojs/components'
3 3
 import './index.scss'
4 4
 
5
-const Layout = ({ children }) => {
6
-    return <ScrollView scrollY className='scrolllayout' >
5
+const Layout = ({ children }, ref) => {
6
+    const scrollRef = useRef()
7
+
8
+    useImperativeHandle(ref, () => ({
9
+        offsetHeight: () => console.log(12312) || scrollRef.current.offsetHeight
10
+    }))
11
+
12
+    return <ScrollView scrollY className='scrolllayout' ref={scrollRef} >
7 13
         <View className='page-container' >
8 14
             {children}
9 15
         </View>
10 16
     </ScrollView>
11 17
 }
12 18
 
13
-
14
-export default Layout;
19
+export default React.forwardRef(Layout);

+ 11
- 8
src/pages/shop/index.jsx Datei anzeigen

@@ -1,4 +1,4 @@
1
-import React, { useEffect, useMemo, useState } from "react";
1
+import React, { useEffect, useMemo, useRef, useState } from "react";
2 2
 import Taro, { useDidShow } from "@tarojs/taro";
3 3
 import "./index.scss";
4 4
 import { View, Text } from "@tarojs/components";
@@ -12,17 +12,15 @@ import IsLogin from "../../layout/IsLogin";
12 12
 const account = props => {
13 13
   const [list, setList] = useState([]);
14 14
   const [page, setPage] = useState({ total: 0, pageNum: 0 });
15
+  const [height, setHeight] = useState(600)
15 16
   const [loading, setLoading] = useState(false);
16 17
 
18
+  const layoutRef = useRef()
19
+
17 20
   const radioHouseState = useMemo(() => props.radioHouseState, [
18 21
     props.radioHouseState
19 22
   ]);
20 23
 
21
-  console.log(props, radioHouseState);
22
-  useEffect(() => {
23
-    
24
-  }, []);
25
-
26 24
   useDidShow(() => {
27 25
     getShopList({ pageNum: 1, pageSize: 10 });
28 26
     // if(page.pageNum==1){
@@ -46,6 +44,11 @@ const account = props => {
46 44
         }else {
47 45
           setList(list.concat(records || []));
48 46
         }
47
+
48
+        const t = setTimeout(() => {
49
+          setHeight(layoutRef.current.offsetHeight() - 10)
50
+          clearTimeout(t)
51
+        }, 500)
49 52
         
50 53
       })
51 54
       .catch(() => setLoading(false));
@@ -107,11 +110,11 @@ const account = props => {
107 110
   return (
108 111
     <IsLogin>
109 112
       <View className="account">
110
-        <Layout>
113
+        <Layout ref={layoutRef}>
111 114
           <InifiniteList
112 115
             length={list.length}
113 116
             total={page.total}
114
-            height={600}
117
+            height={height}
115 118
             itemRenderer={renderItem}
116 119
             loadMore={loadMore}
117 120
           />