angular - 角度无法将条纹导入组件
问题描述
我想以角度创建条纹结帐。逻辑与 stripe 中的示例相同,但我无法在组件类中导入 Stripe:
import {Stripe} from '@stripe/stripe-js';
这是我的用例:
stripe = Stripe("mytoken");
网络风暴 说:
'Stripe' 仅指一种类型,但在这里用作值。
所以我认为导入是错误的,但我实际上不知道如何使用 html 中的脚本。stripe 的示例直接在脚本标记中使用此类:
<script type="text/javascript">
// Create an instance of the Stripe object with your publishable API key
var stripe = Stripe("pk_test_51HaOuLKpHoRFb17FLbnrAQYRee73V3Xc3PzYkOcFmmC9OUbqgY8jW2fDLtNeWOEJKwOfYg9NTKtW1JfDIW2foeel00IsfFQfQW");
var checkoutButton = document.getElementById("checkout-button");
checkoutButton.addEventListener("click", function () {
fetch("/create-session", {
method: "POST",
})
.then(function (response) {
return response.json();
})
.then(function (session) {
return stripe.redirectToCheckout({ sessionId: session.id });
})
.then(function (result) {
// If redirectToCheckout fails due to a browser or network
// error, you should display the localized error message to your
// customer using error.message.
if (result.error) {
alert(result.error.message);
}
})
.catch(function (error) {
console.error("Error:", error);
});
});
解决方案
如果您直接包含 Stripe.js ,您将Stripe('pk_test_123')
用于初始化。
使用@stripe/stripe-js
(用于加载底层stripe.js
资源的包装器),您应该按照使用文档进行初始化loadStripe
:
import {loadStripe} from '@stripe/stripe-js';
const stripe = await loadStripe('pk_test_123');
推荐阅读
- python - 在openCV中检测圆圈
- c++ - QApplication 在共享库中
- java - 如何让 ImageIcon 显示在 JButton 中?
- javascript - React TS - TypeWriter 组件
- laravel - Laravel - cache:clear 命令是否也会清除配置缓存?
- python - 如何验证请求正文是进入 python 烧瓶应用程序的有效 JSON
- spring-boot - 发送html电子邮件的问题
- automation - 空手道 UI 拖放
- ffmpeg - ffmpeg 图像生成输出结果
- java - 检查 char[] 是否仅包含一个字母和一个 int