张延森 4 vuotta sitten
vanhempi
commit
8e2a06e680
2 muutettua tiedostoa jossa 21 lisäystä ja 13 poistoa
  1. 10
    5
      src/layout/index.jsx
  2. 11
    8
      src/pages/shop/index.jsx

+ 10
- 5
src/layout/index.jsx Näytä tiedosto

1
-import React from 'react';
1
+import React, { useRef, useEffect, useImperativeHandle } from 'react';
2
 import { View, ScrollView } from '@tarojs/components'
2
 import { View, ScrollView } from '@tarojs/components'
3
 import './index.scss'
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
         <View className='page-container' >
13
         <View className='page-container' >
8
             {children}
14
             {children}
9
         </View>
15
         </View>
10
     </ScrollView>
16
     </ScrollView>
11
 }
17
 }
12
 
18
 
13
-
14
-export default Layout;
19
+export default React.forwardRef(Layout);

+ 11
- 8
src/pages/shop/index.jsx Näytä tiedosto

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