如何在删除时在甜蜜警报弹出窗口中进行 axios 调用并在弹出窗口内的下拉列表中显示数据?
How do make an axios call inside sweet alert popup on delete and show the data in dropdown inside popup?
我收到一个弹出窗口,显示您确定要删除此数据吗?但我想要的是我想调用 Axios 并在该弹出窗口中获取数据,询问你想将与该数据相关的数据转移到哪里?我想在 sweetalert showing message 的删除弹出窗口中显示下拉列表,你想将与 beacon 相关的内容转移到哪里?并显示包含我从该 axios 调用中获得的信标的下拉菜单
deleteBeacon(beacon) {
swal({
title: "Are you sure?",
text: "Do you really want to delete this beacon?",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
return axios.delete("/beacons/" + beacon.id);
} else {
swal("Cancelled", "Beacon is safe!", "error");
}
})
.then((response) => {
swal("Success", response.data.message, "success");
this.beacons.splice(this.editedIndex, 1);
this.closeDelete();
})
.catch((err) => {
if (err.response.status == 401) {
self.$router.push("/login");
} else if (err.response.status == 404) {
swal(
"Error",
"Beacon does not exists or has been recently removed!",
"error"
);
}
});
},
这是我的删除图标 sweetalert 弹出窗口,
axios.get('/beacons?centerId='+this.form.center_id+'&without='+this.$route.params.id)
这是用于点击和获取数据的 Axios URL,我想在那个甜蜜的警报弹出窗口中显示来自点击此 URL 的数据
您可以创建一个默认隐藏的模板,以在弹出窗口中显示您想要显示的内容
import swal from "sweetalert";
export default {
name: "App",
data: function() {
return {
beaconsInfos: [],
isShowSwalTemplate: false,
};
},
methods: {
fakeGetBeaconsInfo: function(fakeId) {
return new Promise((resolve) => {
setTimeout(() => {
resolve([{
value: "first_" + fakeId,
},
{
value: "second_" + fakeId,
},
{
value: "third_" + fakeId,
},
]);
}, 1000);
});
},
deleteBeacon: function() {
const fakeBeacon = {
id: +new Date(),
};
this.fakeGetBeaconsInfo(fakeBeacon.id).then((beaconsInfos) => {
// refresh dropdown source
this.beaconsInfos = beaconsInfos;
// show popup
swal(this.$refs["swal-template"]);
this.isShowSwalTemplate = true;
});
},
},
};
<template>
<div>
<button @click="deleteBeacon">delete beacon</button>
<div v-show="isShowSwalTemplate" ref="swal-template">
<select>
<option v-for="beaconsInfo in beaconsInfos" :key="beaconsInfo.value">
{{ beaconsInfo.value }}
</option>
</select>
</div>
</div>
</template>
我收到一个弹出窗口,显示您确定要删除此数据吗?但我想要的是我想调用 Axios 并在该弹出窗口中获取数据,询问你想将与该数据相关的数据转移到哪里?我想在 sweetalert showing message 的删除弹出窗口中显示下拉列表,你想将与 beacon 相关的内容转移到哪里?并显示包含我从该 axios 调用中获得的信标的下拉菜单
deleteBeacon(beacon) {
swal({
title: "Are you sure?",
text: "Do you really want to delete this beacon?",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
return axios.delete("/beacons/" + beacon.id);
} else {
swal("Cancelled", "Beacon is safe!", "error");
}
})
.then((response) => {
swal("Success", response.data.message, "success");
this.beacons.splice(this.editedIndex, 1);
this.closeDelete();
})
.catch((err) => {
if (err.response.status == 401) {
self.$router.push("/login");
} else if (err.response.status == 404) {
swal(
"Error",
"Beacon does not exists or has been recently removed!",
"error"
);
}
});
},
这是我的删除图标 sweetalert 弹出窗口,
axios.get('/beacons?centerId='+this.form.center_id+'&without='+this.$route.params.id)
这是用于点击和获取数据的 Axios URL,我想在那个甜蜜的警报弹出窗口中显示来自点击此 URL 的数据
您可以创建一个默认隐藏的模板,以在弹出窗口中显示您想要显示的内容
import swal from "sweetalert";
export default {
name: "App",
data: function() {
return {
beaconsInfos: [],
isShowSwalTemplate: false,
};
},
methods: {
fakeGetBeaconsInfo: function(fakeId) {
return new Promise((resolve) => {
setTimeout(() => {
resolve([{
value: "first_" + fakeId,
},
{
value: "second_" + fakeId,
},
{
value: "third_" + fakeId,
},
]);
}, 1000);
});
},
deleteBeacon: function() {
const fakeBeacon = {
id: +new Date(),
};
this.fakeGetBeaconsInfo(fakeBeacon.id).then((beaconsInfos) => {
// refresh dropdown source
this.beaconsInfos = beaconsInfos;
// show popup
swal(this.$refs["swal-template"]);
this.isShowSwalTemplate = true;
});
},
},
};
<template>
<div>
<button @click="deleteBeacon">delete beacon</button>
<div v-show="isShowSwalTemplate" ref="swal-template">
<select>
<option v-for="beaconsInfo in beaconsInfos" :key="beaconsInfo.value">
{{ beaconsInfo.value }}
</option>
</select>
</div>
</div>
</template>