加载Google Pay Ionic 3的离子库

问题描述 投票:0回答:1

我正在尝试在我的Ionic应用中实施Google Pay。由于找不到适合两者的便捷库,因此我尝试使用此处描述的内容

https://developers.google.com/pay/api/web/guides/tutorial#full-example

问题:加载pay.js库

enter image description here

我不知道如何在Ionic项目中加载库pay.js。

我希望很清楚。

感谢您的帮助。

ionic-framework ionic3 google-pay
1个回答
0
投票
您首先需要包含pay.js库。

首选方法是在页面中包含脚本:

<script src="https://pay.google.com/gp/p/js/pay.js" async></script>

或者,如果需要使用JavaScript加载,则可以dynamically load the script

function loadScript(src) { return new Promise(function(resolve, reject) { let script = document.createElement('script'); script.src = src; script.onload = () => resolve(script); script.onerror = () => reject(new Error(`Script load error for ${src}`)); document.head.append(script); }); } loadScript('https://pay.google.com/gp/p/js/pay.js') .then(() => getGooglePayPaymentsClient());

要在受支持的编辑器中完成代码,可以使用@types/googlepay包:

npm install --save-dev @types/googlepay

© www.soinside.com 2019 - 2024. All rights reserved.