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. 【BZOJ】3139: [Hnoi2013]比赛

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3139 可以发现,答案之和得分的序列有关,而且和序列中每个元素的顺序无关.考虑HASH所有的 ...

  2. hdu 1115 Lifting the Stone 多边形的重心

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  3. Java——HashMap

    获取数组长度 数组.length 获取下标 HashMap HashMap 构造函数 // 默认构造函数. HashMap() // 指定“容量大小”的构造函数 HashMap(int capacit ...

  4. "不是内部或外部命令"

    问题描述: 使用cmd 运行某个路径下(一般是C:PROGRAM FILES\...或者E:\program files\....或者D:\program files\......下面的某个)的exe ...

  5. 学习笔记2—MATLAB的copyfile技巧

    clearclc %一.新建文件夹,%二.将原始路径下的数据剪切到新建文件夹中 path = ('E:\DFC_DMN_ASD_DATA_res\Cluster_hcc\4,6,8\Cluster_6 ...

  6. ssh连接docker镜像ubuntu与debian

    用密码登录root docker官网给的sshdemo是ubuntu的,https://docs.docker.com/engine/examples/running_ssh_service/   亲 ...

  7. HTML标记 2 ——表格

    <table width="800" border="0">     -----------------------表开头 <tr>   ...

  8. 手动增删windows 服务和dll函数

    ①注册windows服务 sc create "服务名AAA" binPath= "安装目录\AAA.exe" displayname= "服务显示名 ...

  9. winfrom 动态添加控件,以及删除

      private void btnadd_Click(object sender, EventArgs e)         {             int fileCount = 0;     ...

  10. php后台操作以及一些减缓服务器压力的问题

    上次提到一个微信投票系统,做了一个微信重定向解决了,一个授权复用的问题,昨天投票系统正式投入使用:测试的时候没有问题,上线后出现了一点小问题, 一:php页面参数接受和php中 switch 那个先执 ...