我想在另一个组件(Next.js,React.js)中使用一个部件

kpbwa7wx  于 2023-08-04  发布在  React
关注(0)|答案(1)|浏览(108)

我想在“index.tsx”中使用“StyledSwiperPagination(swiper-pagination-bullet)atSwiperImages.tsx”。
问题是我

<StyledSwiperPagination />

字符串
但是没有显示任何内容。
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

SwiperImages.tsx

import "swiper/css";
import "swiper/css/navigation";
import "swiper/css/pagination";
import "swiper/css/thumbs";
import { ProductThumbnailImage } from "../ProductList/ProductThumbnailImage";

import "photoswipe/dist/photoswipe.css";

type Props = {
  images: ProductImageUrlFragment[];
};

export const SwiperImages: React.FC<Props> = ({ images }) => {
  const [thumbsSwiper, setThumbsSwiper] = useState<any>(null);
  const [height, setHeight] = useState(0);
  const [width, setWidth] = useState(0);

  useEffect(() => {
    setHeight(window.innerHeight);
    setWidth(window.innerWidth);
  }, []);

  const [isPc] = useMediaQuery("(min-width: 960px)", { ssr: false });
  const padding = isPc
    ? { top: 100, bottom: 100, left: 100, right: 100 }
    : { top: 0, bottom: 0, left: 0, right: 0 };

  return (
    <StyledSwiperPagination length={images.length}>
      <Gallery
        options={{
          showHideOpacity: true,
          hideAnimationDuration: 0,
          padding: padding,
          loop: false,
        }}
      >
        <Swiper
          modules={[Navigation, Pagination, Thumbs]}
          spaceBetween={0}
          slidesPerView={1}
          navigation
          pagination={{ clickable: true, type: "bullets" }}
          thumbs={{
            swiper:
              thumbsSwiper && !thumbsSwiper.destroyed ? thumbsSwiper : null,
          }}
        >
        .
        .
        .
        </Swiper>
      </Gallery>

    </StyledSwiperPagination>
  );
};

export const StyledSwiperPagination = styled.div<{ length: number }>`
  .swiper-button-next,
  .swiper-button-prev {
    color: ${colors.brand.black} !important;
    background-color: rgba(255, 255, 255, 0.5) !important;
    border-radius: 100px !important;
    width: 24px !important;
    height: 24px !important;
    line-height: 24px !important;
    ::after {
      font-size: 10px !important;
    }
    &.swiper-button-disabled {
      display: none !important;
    }
  }

  .swiper-pagination {
    padding: 0px 9px !important;

    .swiper-pagination-bullet {
      margin: 0px 10px !important;
      padding: 0px !important;
      height: 20px !important;
      width: 20px !important;
      border-radius: 50% !important; 
      border: 2px solid #fff !important; 
      background-color: #fff !important;
      opacity: 0.5 !important;
    }
  
    .swiper-pagination-bullet-active {
      border: 2px solid #000 !important; 
      background-color: #000 !important; 
      opacity: 1 !important;
    }
  }

  .pcThumbnailGrid {
    padding: 2px 0;
    margin-bottom: 120px;

    display: none;
    @media ${targetPlatformMedia.largeDesktop} {
      display: block;
    }

    .swiper-wrapper {
      display: grid;
      grid-template-columns: repeat(5, 1fr);
      row-gap: 2px;
    }
    .swiper-slide {
      cursor: pointer;
    }
    .swiper-slide-thumb-active {
      opacity: 0.8;
      border-bottom: 1px solid black;
  }
`;

index.tsx

import { StyledSwiperPagination } from "~/components/elements/SwiperImages";
.
.
.
const ProductDetailPage: NextPage<Props> = ({

.
.
.

  return (
        <Flex>
          <StyledSwiperPagination  />
        </Flex>

.
.
.

export default ProductDetailPage;

nx7onnlm

nx7onnlm1#

你能提供这段代码是哪个版本的Nextjs吗
寻呼路由器/应用路由器
因为Pager-router和App-router导入和导出组件的方法不同

相关问题