亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

類型錯誤:document.querySelectorAll 不是函數

類型錯誤:document.querySelectorAll 不是函數

月關寶盒 2023-12-14 15:33:04
我正在使用 Meteor 框架和 React。添加了@stripe包。付款表單有效,但它不斷在日志中顯示以下內容:UnhandledPromiseRejectionWarning: TypeError: document.querySelectorAll is not a functionat findScript (/project/node_modules/@stripe/stripe-js/dist/stripe.js:9:26)at /project/node_modules/@stripe/stripe-js/dist/stripe.js:75:20at new Promise (<anonymous>)at loadScript (/project/node_modules/@stripe/stripe-js/dist/stripe.js:57:19)at /project/node_modules/@stripe/stripe-js/dist/stripe.js:113:10at /.meteor/packages/promise/.0.11.2.1e1wn8z.joczg++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:40我怎么解決這個問題?
查看完整描述

1 回答

?
犯罪嫌疑人X

TA貢獻2080條經驗 獲得超4個贊

這似乎是您在服務器上看到的錯誤(否則路徑node_modules將不會顯示)。所以看來您正在嘗試在服務器端渲染條紋形式。這不起作用,因為服務器上不存在該功能。我認為最好的選擇是在使用這種條紋形式的反應組件中添加一個防護。像這樣的東西:


const MyPaymentForm = (props) => {


  if (Meteor.isServer) {

    return <div>Stripe form will load dynamically on client</div>;

  }


  render <div suppressHydrationWarning={true}>

    <StripeProviver>...</StripeProvider>

  </div>;

};

客戶端版本上的參數suppressHydrationWarning是為了避免有關水合 HTML 的(常見)React 錯誤,該錯誤在客戶端上的形狀與從服務器返回的形狀不同。


查看完整回答
反對 回復 2023-12-14
  • 1 回答
  • 0 關注
  • 247 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號