import Vue from 'vue'
import { ToastPlugin, AlertPlugin, ConfirmPlugin, LoadingPlugin } from 'vux'
/*import { Promise } from 'es6-promise';*/
 
Vue.use(ToastPlugin)
Vue.use(AlertPlugin)
Vue.use(ConfirmPlugin)
Vue.use(LoadingPlugin)
 
const Message = {};
Message.install = () => {
    const msg = {
        $toast: config => {
            let def = {
                type:'text',
                text:''
            }
            if(typeof  config  === 'string' || typeof  config  === 'number'){
                Vue.$vux.toast.show({type:'text',text:config})
            }else{
                Vue.$vux.toast.show(Object.assign(def,config))
            }
 
        },
        $alert: config => {
            let def = {
                title:'提示',
                content:'系统异常,请重新登录后再试!',
                buttonText:'确定'
            }
            if(typeof  config  === 'string' || typeof  config  === 'number'){
                Vue.$vux.alert.show(Object.assign(def,{content:config}));
            }else{
                Vue.$vux.alert.show(Object.assign(def,config));
            }
        },
        $confirm: config => {
            let isConfirm = false;
            let def = {
                title:'提示',
                content:'系统异常,请重新登录后再试!',
                confirmText:'确定',
                cancelText:'取消',
                onConfirm:() =>{
                    isConfirm = true;
                }
            }
            if(typeof  config  === 'string' || typeof  config  === 'number'){
                Vue.$vux.confirm.show(Object.assign(def,{content:config}));
            }else{
                Vue.$vux.confirm.show(Object.assign(def,config));
            }
            /*return new Promise((resolve,reject) => {
                if(isConfirm){
                    resolve();
                }
            })*/
        },
        $showLoading: config => {
            let def = {
                text: '加载中...'
            }
            if(typeof  config  === 'string' || typeof  config  === 'number'){
                Vue.$vux.loading.show(Object.assign(def,{text:config}));
            }else{
                Vue.$vux.loading.show(Object.assign(def,config));
            }
        }
 
    }
    Object.entries(msg).forEach(([method,fn]) => {
        Vue.prototype[method] = fn;
    })
}
Vue.use(Message)

vue中alert toast confirm loading 公用的更多相关文章

  1. 去掉网页中alert和confirm弹出框自带的网址

    去掉网页中alert和confirm弹出框自带的网址 Alert: <script> window.alert = function(name){ var iframe = documen ...

  2. vue 中使用 Toast弹框

    import { ToastPlugin,ConfirmPlugin,AlertPlugin} from 'vux' Vue.use(ToastPlugin) Vue.use(ConfirmPlugi ...

  3. Vue自定义全局Toast和Loading

    如果我们的Vue项目中没有用到任何UI框架的话,为了更好的用户体验,肯定会用到loading和toast.那么我们就自定义这两个组件吧. 1.Toast组件 首先,在common下新建global文件 ...

  4. Vue 中使用 extent 开发loading等全局 组件

    Vue 中使用 extend 开发组件 简介:再开发过程中那面会遇到自定义 loading alert 等全局组件,这里我们可以使用 vue 中的extend 来帮助我们完成 一个简单extend例子 ...

  5. vue中的toast组件

    首先在components新建组件文件夹 随后在toast.vue中写入弹框样式 <template> <transition name="demo"> & ...

  6. vue中自定义组件(插件)

    vue中自定义组件(插件) 原创 2017年01月04日 22:46:43 标签: 插件 在vue项目中,可以自定义组件像vue-resource一样使用Vue.use()方法来使用,具体实现方法: ...

  7. Ionic4.x Javascript 扩展 ActionSheet Alert Toast Loading 以及 ionic 手势相 关事件

    1.ActionSheet 官方文档:https://ionicframework.com/docs/api/action-sheet <ion-header> <ion-toolb ...

  8. Bootstrap Modal 框 alert confirm loading

    /** * Created by Administrator on 2016/5/4. */ /** * 模态窗口 */ window.Modal = { tpls:{ alert:'<div ...

  9. Android线程中使用Toast、dialog、loading

    代码改变世界 Android线程中使用Toast.dialog.loading Loading: Thread t1 = new Thread(new Runnable() { @Override p ...

随机推荐

  1. java stackoverflowerror与outofmemoryerror区别(转)

    1.stackoverflow: 每当java程序启动一个新的线程时,java虚拟机会为他分配一个栈,java栈以帧为单位保持线程运行状态:当线程调用一个方法是,jvm压入一个新的栈帧到这个线程的栈中 ...

  2. zzulioj 1206 字符串的修改 (字符串修改)

    不难,理解一下直接过,代码如下: #include<stdio.h> #include<string.h> #include<math.h> #include< ...

  3. 删除GitHub或者GitLab 上的文件夹,git rm -r --ceched 文件夹名 ,提交commit,git push

    方法一 这里以删除 .setting 文件夹为案例 git rm -r --cached .setting #--cached不会把本地的.setting删除 git commit -m 'delet ...

  4. 学习笔记22—PS小技巧

    1.将图片四角变弧形:菜单-->选择-->平滑-->设置参数: 2.画曲线的方法是: 1)选择钢笔工具, 2)工具属性选择路径:用钢笔点下路径的起点,点下即松开鼠标:在下一个锚点,点 ...

  5. [MySQL]典型的行列转换

    列变成行 测试数据库数据样式: 应用的sql语句: SELECT TM,NAME,SUM(GE) AS 'GE',SUM(GD) AS 'GD',SUM(CT) AS 'CT',SUM(NUM) AS ...

  6. ionic 搜索双向数据绑定失效

    1.用data对象存储变化的数据 js: $scope.data={}; $scope.data.keywords = ""; $scope.search = function() ...

  7. Unity --- MeshRenderer之网格合并

    创建如图所示的对象结构,parent为空对象,然后将下面的代码挂载到parent对象上运行即可. using UnityEngine; using System.Collections; public ...

  8. Ubuntu下安装Google浏览器

    和其他软件一样,比较常用的安装方法. 1.下载deb包对于谷歌Chrome32位版本,使用如下链接:wget https://dl.google.com/linux/direct/google-chr ...

  9. InitializingBean和DisposableBean

    InitializingBean 记住一点:InitializingBean接口为bean提供了初始化方法的方式,它只包括afterPropertiesSet方法,凡是继承该接口的子类,在初始化bea ...

  10. LeetCode--258--各位相加*

    问题描述: 给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数. 示例: 输入: 38 输出: 2 解释: 各位相加的过程为:3 + 8 = 11, 1 + 1 = 2. 由于 2 ...