相关疑难解决方法(0)

Next.js:文档未定义

我正在尝试创建一个人们可以付款的付款表格,但我不断收到此错误。

文档未定义

我正在使用 Next.js。请看我下面的代码:

import React from "react";
import {Elements, StripeProvider} from 'react-stripe-elements';
import CheckoutForm from '../../components/Payment/CheckoutForm';
import { useRouter } from 'next/router';


var stripe_load = () => {
    var aScript = document.createElement('script');
    aScript.type = 'text/javascript';
    aScript.src = " https://js.stripe.com/v3/";

    document.head.appendChild(aScript);
    aScript.onload = () => {

    };
};

function Payment({host}) {
    const key = host.includes('localhost') ? 'test' : 't';

    stripe_load();

    const router = useRouter();

    return (
        <div className="Payment Main">
            <StripeProvider apiKey={key}>
                <Elements>
                    <CheckoutForm planid={router.query.id}/>
                </Elements>
            </StripeProvider>
            <br/>
            <br/>
            <p>Powered by …
Run Code Online (Sandbox Code Playgroud)

node.js reactjs next.js

27
推荐指数
6
解决办法
4万
查看次数

标签 统计

next.js ×1

node.js ×1

reactjs ×1