import React from 'react' import { Image, Text, View } from '@tarojs/components' import './index.scss' import TabbarAction from '@/components/action'; import { Infiniteloading } from '@nutui/nutui-react-taro'; import { useEffect } from 'react'; import { useState } from 'react'; import { mallList } from '../../utils/api'; import Taro from '@tarojs/taro'; function Index() { const limit = 10 const [list, setList] = useState([]) const [total, setTotal] = useState(0) const [page, setPage] = useState(1) const [hasMore, setHasMore] = useState(true) useEffect(() => { if (page < 1) { return } fetchList(page) }, [page]) const fetchList = async (page) => { const offset = (page - 1) * limit const res = await mallList('mall', offset, limit) if (!res) return if (res.items?.length + list.length >= res.total) { setHasMore(false) } setList(res.items) setTotal(res.total) } // 跳转 const navDetailFn = (id) => { Taro.navigateTo({ url: `/pages/goods-detail/index?id=${id}` }) } return ( 首页 } loadIcon='loading' hasMore={hasMore} onLoadMore={(x) => { setPage(p => p + 1) x() }} > { list.map(item => { return { navDetailFn(item.id) }}> {item.name} {/* 这个是商品的介绍 */} ¥{item.price} {/* 原价888 */} }) } ) } export default Index