版本??"next": "14.0.4",??"antd-mobile": "^5.34.0",
next中使用antd-mobile可困难了.主要是因为antd-mobile不支持ssr
1.下载antd-mobile包,在next.config.js中加入
transpilePackages: [
'antd-mobile',
],
2.在页面中引入antd-mobile组件
然后就报错了
import Head from "next/head";
import Image from "next/image";
import { Inter } from "next/font/google";
import styles from "@/styles/Home.module.css";
import { Button } from "antd-mobile";
const inter = Inter({ subsets: ["latin"] });
export default function Home() {
return (
<>
<Button></Button>
</>
);
}
3.使用next的dynamic
import dynamic from "next/dynamic";
const Active = dynamic(() => import("../components/home/active"), {
ssr: false,
});
把引入antdmobile 的那个组件用非ssr的方式引入
然后能正常使用,但是好麻烦.只要用到antdmobile的组件都得用非ssr的方式引入.去找找更好的方法