vue.js - 为什么此代码的 axios 响应为空?
问题描述
我收到控制台消息:
“IntegrationError:stripe.redirectToCheckout:您必须提供 lineItems、items 或 sessionId 之一。”
我相信 sessionId 是空的,因为 response.data 是来自 console.log(response.data)的“空字符串”。
这段代码来自一个教程的github。它应该非常接近正确,但我相信有一点不准确。
stripe.checkout.sessions.create({
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
payment_method_types: ["card"],
line_items: results
}, function(err, session) {
response.send(session)
});
axios.get('https://us-central1-webstore-vuejs.cloudfunctions.net/CheckoutSession', {
params: {
products: data
}
}).then(response => {
this.sessionId = response.data
console.log(response.data)
stripe.redirectToCheckout({
sessionId: this.sessionId.id
}).then(function(result) {
});
})
解决方案
}, function(err, session) {
response.send(session)
});
我怀疑您在这里发生了错误;我会记录它,看看它可能是什么。
理想情况下,您应该始终至少抛出(或理想情况下处理!)错误,以便您知道何时出现问题。
推荐阅读
- node.js - React Native 无法运行成功的 fetch 来表达 API
- javascript - jquery过滤元素,元素增加时的速度问题
- c# - ASP.NET Web API 每秒返回数据
- java - 如何通过按钮操作将字符串传递给类
- javascript - CSS 和语义 ui cdn 在 localhost 中不起作用
- ruby - Ruby 就地排序子数组
- c++ - morphologyEx 是否应该使用矩阵元素作为边框像素?
- c# - Ag-grid - 在 Angular 7 中设置层次结构和总数
- r - R:具有嵌套函数的非标准评估
- d3.js - 创建由多个域组成的规模