【问题标题】:snipcart error: public API key not found. Attribute data-api-key must be set on #snipcart tagsnipcart 错误:未找到公共 API 密钥。必须在#snipcart 标签上设置属性 data-api-key
【发布时间】:2020-10-20 20:49:28
【问题描述】:

我在正确加载 snipcart 时遇到问题,它会在 localhost 上获取 api 键并显示购物车中的物品数量,但是当部署到 netlify 时,它会在页面加载时短暂闪烁购物车中的物品数量,指示api密钥是正确的,但是它会出现错误 public API key not found. Attribute data-api-key must be set on #snipcart tag.

我正在使用 react 来渲染它,并已将其简化为最小样板,以查看 react 中是否有任何内容可能导致此问题,但我仍然遇到同样的问题。

<div hidden id="snipcart" data-api-key={{ API_KEY }}></div> 移动到app.js 文件并且它可以工作,但在index.html 它不起作用

index.html

<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge"> 
    <link href ="https://fonts.googleapis.com/css2?family=Open+Sans&family=Lexend+Zetta&family=Poppins:wght@400;500;700&family=Shadows+Into+Light&display=swap" rel="stylesheet">
    <link rel="preconnect" href="https://app.snipcart.com">
    <link rel="preconnect" href="https://cdn.snipcart.com">
    <link rel="stylesheet" href="https://cdn.snipcart.com/themes/v3.0.23/default/snipcart.css" />
  </head>

  <body>
    <div id="root"></div>
    <script async src="https://cdn.snipcart.com/themes/v3.0.23/default/snipcart.js"></script>
    <div hidden id="snipcart" data-api-key={{ API_KEY }}></div>
  
    <script src="./index.tsx"></script>
    
  </body>

</html>

【问题讨论】:

    标签: javascript reactjs snipcart


    【解决方案1】:

    把它放在你的 html 中是行不通的,因为 {{API_KEY}} 是我从你的框架中假设的。由于 html 代码不是使用您的框架编译的,它不会对

    【讨论】:

      猜你喜欢
      • 2020-04-25
      • 2011-12-22
      • 2017-05-31
      • 2020-10-22
      • 1970-01-01
      • 2020-03-22
      • 1970-01-01
      • 2022-01-27
      • 1970-01-01
      相关资源
      最近更新 更多