如何将脚本传递给功能组件

  • 本文关键字:功能 组件 脚本 reactjs
  • 更新时间 :
  • 英文 :


如何将脚本传递给功能组件。我想在react中创建的应用程序中显示一个支付按钮。

脚本从以下链接获取:https://docs.livepayphone.com/knowledge-base/expresscheckout/?unapproved=1933& moderation-hash = 3284 f081dabdbc0412309ac9236d38cf #评论- 1933

脚本如下:

<script>
window.onload = function() {
payphone.Button({
token: TOKEN,
btnHorizontal: true,
btnCard: true,
createOrder: function(actions){
return actions.prepare({
amount: 100,
amountWithoutTax: 100,
currency: "USD",
clientTransactionId: ID_TRANSACTION
});
},
onComplete: function(model, actions){
actions.confirm({
id: model.id,
clientTxId: model.clientTxId
}).then(function(value){
console.log(VALUE);
}).catch(function(err){
console.log(err);
});
}
}).render(‘#pp-button’);
}
</script>

将脚本放在正文的底部public/index.html没有渲染函数。

像这样:

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
<script>
window.onload = function () {
payphone.Button({
token: TOKEN,
btnHorizontal: true,
btnCard: true,
createOrder: function (actions) {
return actions.prepare({
amount: 100,
amountWithoutTax: 100,
currency: "USD",
clientTransactionId: ID_TRANSACTION
});
},
onComplete: function (model, actions) {
actions.confirm({
id: model.id,
clientTxId: model.clientTxId
}).then(function (value) {
console.log(VALUE);
}).catch(function (err) {
console.log(err);
});
}
});
}
</script>
</body>

确保在头部中也添加了cdn公众/index . html

<script src=»https://pay.payphonetodoesposible.com/api/button/js?appId=ACATUIDDEAPLICACION»></script>
然后在react应用的任何地方用id: pp-button创建一个按钮
<button id="pp-button">Button</button>

最新更新