如何在vue中创建警报确认框 [英] how to create alert confirm box in vue

查看:430
本文介绍了如何在vue中创建警报确认框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在删除文件之前显示一个对话框,我该如何使用vue?

i want to show a dialog box before deleting a files, how i can do it with vue?

这是我尝试的

我的按钮,用于删除文件

my button to delete a file

<a href="javascript:;" v-on:click="DeleteUser(artist.id, index)" onClick="return confirm('are you sure?');">Delete</a>

这里是我的删除方法

DeleteUser(id, index) {
                axios.delete('/api/artist/'+id)
                .then(resp => {
                    this.artists.data.splice(index, 1);
                })
                .catch(error => {
                    console.log(error);
                })
            },

对话框显示,但是无论选择什么,都会删除该文件.

the dialog is showing but whatever i choose it keep delete the file.

推荐答案

尝试一下

<a href="javascript:;" v-on:click="DeleteUser(artist.id, index)">Delete</a>

DeleteUser(id, index) {

   if(confirm("Do you really want to delete?")){

                axios.delete('/api/artist/'+id)
                .then(resp => {
                    this.artists.data.splice(index, 1);
                })
                .catch(error => {
                    console.log(error);
                })
   }
},

这篇关于如何在vue中创建警报确认框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆