首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将值从didOpen sweetalert2参数传递到.then

将值从didOpen sweetalert2参数传递到.then
EN

Stack Overflow用户
提问于 2020-10-16 03:41:19
回答 1查看 1.4K关注 0票数 0

我已经构建了didOpen参数,并实现了一个内部带有值的JSON对象。

问题是。如何将JSON对象传递给Swal.fire({ }) .then箭头函数then部分

代码语言:javascript
运行
复制
Swal.fire({
  html: ` HERE IS ALL THE ID's STUFF `,
  didOpen() {
    let itemPOST = {
      /* the json i trying to catch */ }

    // do bunch of stuff and save it into itemPOST

  } //==>end of didOpen
}).then(() => {
  //console log here for itemPOST
})
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-16 21:56:38

解决方案是在swal之后包含一些变量,将值传递给该变量并在.then()箭头函数中调用它

代码语言:javascript
运行
复制
let giveMeTheValue;  //<==    variable to receive the value
Swal.fire({
  html: ` HERE IS ALL THE ID's STUFF `,
  didOpen() {
    let itemPOST = { /* the json with data */ }

    // do bunch of stuff and save it into itemPOST

    giveMeTheValue = itemPOST   //<== giving the data to pass to then()
  } 
}).then(() => {
  console.log(giveMeTheValue)
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64378624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档