在vue裏面使用 vue-sweetalertvue
npm install vue-sweetalert --save import VueSweetAlert from 'vue-sweetalert' Vue.use(VueSweetAlert)
完整例子:(不須要的選項就不要設置,詳情看文檔)git
this.$swal({ title: '', // 標題 text: 'You will not be able to recover this imaginary file!', // 文本 type: 'warning', // 類型 timer: 2000, // 彈框顯示時間 showCancelButton: true, confirmButtonColor: '#DD6B55', confirmButtonText: 'Yes, delete it!' }).then(() => { // 點擊確認按鈕執行的操做 this.$swal('Deleted!', 'Your imaginary file has been deleted.', 'success') }, () => { // 點擊取消按鈕執行的操做 this.$swal('Cancle!', 'Your imaginary file has been cancled.', 'success') }).catch(this.$swal.noop) // 解決在vue中使用時的報錯
我在使用過程報錯的幾個地方github
解決:添加這樣代碼catch(this.$swal.noop)
npm
this.$swal({...}).catch(this.$swal.noop)
緣由: 版本修改 Migration from SweetAlert to SweetAlert2 跟前面的文檔個別選項設置有衝突,本項目看這個promise
第一、2種oop
this.$swal({ title: 'Title', text: 'You will not be able to recover this imaginary file!', }).catch(this.$swal.noop)
第3種this
this.$swal({ title: '', // 標題 text: 'You will not be able to recover this imaginary file!', // 文本 type: 'warning', // 類型 timer: 2000, // 彈框顯示時間 showCancelButton: true, confirmButtonColor: '#DD6B55', confirmButtonText: 'Yes, delete it!' }).then(() => { // 點擊確認按鈕執行的操做 this.$swal('Deleted!', 'Your imaginary file has been deleted.', 'success') }, () => { // 點擊取消按鈕執行的操做 this.$swal('Cancle!', 'Your imaginary file has been cancled.', 'success') }).catch(this.$swal.noop) // 解決在vue中使用時的報錯