聊聊vue集成sweetalert2提示組件的問題
一、項目集成
官網(wǎng)鏈接:https://sweetalert2.github.io
案例
1. 引入方式 CDN引入方式:
在index.html中全局引入
<script src="http://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
位置:
npm安裝方式:
npm install sweetalert2
2. 確認框封裝
Confirm = { show: function (message, callback) { Swal.fire({ title: '確認 ?', text: message, icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: '是的, 已確認!' }).then((result) => { if (result.isConfirmed) { if (callback) { callback() } } }) } }
3. 提示框封裝
Toast = { success: function (message) { Swal.fire({ position: 'top-end', icon: 'success', title: message, showConfirmButton: false, timer: 3000 }) }, error: function (message) { Swal.fire({ position: 'top-end', icon: 'error', title: message, showConfirmButton: false, timer: 3000 }) }, warning: function (message) { Swal.fire({ position: 'top-end', icon: 'warning', title: message, showConfirmButton: false, timer: 3000 }) } };
4. 確認框使用
/** * 點擊【刪除】 */ del(id) { let _this = this Confirm.show("刪除后不可恢復, 確認刪除 !", function () { Loading.show() _this.$api.delete('http://127.0.0.1:9000/business/admin/chapter/delete/' + id).then((res) => { Loading.hide() console.log("刪除大章列表結(jié)果:", res) let resp = res.data if (resp.success) { _this.list(1) Swal.fire( '刪除成功!', '刪除成功!', 'success' ) } }) })
5. 消息提示框使用
/** * 點擊【保存】 */ save() { let _this = this Loading.show() _this.$api.post('http://127.0.0.1:9000/business/admin/chapter/save', _this.chapter).then((res) => { Loading.hide() console.log("保存大章列表結(jié)果:", res) let resp = res.data if (resp.success) { $("#form-modal").modal("hide") _this.list(1) Toast.success("保存成功!") } else { Toast.warning(resp.message) } }) }
6.項目效果
到此這篇關(guān)于vue 集成 sweetalert2 提示組件的文章就介紹到這了,更多相關(guān)vue 集成 sweetalert2內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue.js實現(xiàn)的全選與全不選功能示例【基于elementui】
這篇文章主要介紹了vue.js實現(xiàn)的全選與全不選功能,結(jié)合實例形式分析了vue.js基于elementui實現(xiàn)全選與全不選功能的相關(guān)頁面渲染、初始化數(shù)據(jù)及功能函數(shù)等相關(guān)操作技巧,需要的朋友可以參考下2018-12-12去掉vue 中的代碼規(guī)范檢測兩種方法(Eslint驗證)
我們在使用vue 腳手架時,為了規(guī)范團隊的代碼格式,會有一個代碼規(guī)范檢測,如果不符合規(guī)范就會報錯,有時候我們不想按照他的規(guī)范去寫。這時我們需要關(guān)閉,這里腳本之家小編給大家?guī)砹巳サ魐ue 中的代碼規(guī)范檢測兩種方法(Eslint驗證),一起看看吧2018-03-03elementUI vue this.$confirm 和el-dialog 彈出框 移動 示例demo
這篇文章主要介紹了elementUI vue this.$confirm 和el-dialog 彈出框 移動 示例demo,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-07-07