【问题标题】:Ionic 3 loading Google Pay libraryIonic 3 加载 Google Pay 库
【发布时间】:2020-03-31 14:20:30
【问题描述】:

我正在尝试在我的 Ionic 应用中实施 Google Pay。由于我没有找到任何方便的库匹配两者,我尝试使用这里描述的内容

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

问题:加载 pay.js 库

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

我希望这很清楚。

感谢您的帮助。

【问题讨论】:

    标签: ionic-framework ionic3 google-pay


    【解决方案1】:

    您需要先包含 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-04
      • 2017-11-20
      • 2018-09-09
      • 2021-09-11
      • 2017-03-12
      • 1970-01-01
      • 1970-01-01
      • 2016-12-15
      相关资源
      最近更新 更多