问题描述
我已经构建了didOpen参数,并实现了一个内部包含值的JSON对象。
问题是...如何将JSON对象传递给Swal.fire({})的随后部分。然后使用箭头功能
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
})
解决方法
解决方案是在swal之后包含一些变量,将值传递给该变量,然后在.then()箭头函数中调用它
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)
})