【问题标题】:How do make an axios call inside sweet alert popup on delete and show the data in dropdown inside popup?如何在删除时在甜蜜警报弹出窗口中进行 axios 调用并在弹出窗口内的下拉列表中显示数据?
【发布时间】:2021-10-06 22:20:23
【问题描述】:

我收到一个弹出窗口,显示您确定要删除此数据吗?但是我想要的是我想进行 Axios 调用并在该弹出窗口中获取数据,询问您要将与该数据相关的数据转移到哪里?我想在 sweetalert 显示消息的删除弹出窗口中显示下拉菜单,您想将与信标相关的内容转移到哪里?并显示包含我从该 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 的数据

【问题讨论】:

标签: laravel vue.js vue-component vuetify.js sweetalert2


【解决方案1】:

您可以创建一个默认隐藏的模板以在弹出窗口中显示您想要显示的内容

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>

【讨论】:

  • 我想我无法让你理解我的问题。我想在 sweetalert 显示消息的删除弹出窗口中显示下拉菜单,您想将与信标相关的内容转移到哪里?并显示包含我从该 axios 调用中获得的信标的下拉列表
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-29
  • 1970-01-01
  • 1970-01-01
  • 2013-01-13
  • 1970-01-01
  • 1970-01-01
  • 2013-08-27
相关资源
最近更新 更多