Vue 添加全局Toast和Confirm

2020-11-26 08:41:36

vue添加全局Toast和Confirm

var common = {
        Toast: function (msg = 'tip', callback, timeout = 2000) {
            let LoadingTip = Vue.extend({
                template: `<div class="toast-con"><div class="info"><span>${msg}</span></div></div>`
            })

            // 2、创建实例,挂载到文档以后的地方
            let tpl = new LoadingTip().$mount().$el
            // 3、把创建的实例添加到body中
            document.body.appendChild(tpl);

            setTimeout(function() {
                document.body.removeChild(tpl);
                callback && callback();
            },timeout);
        },

        Confirm: function (title='提示', content, callback) {
            let LoadingTip = Vue.extend({
                template: `<div class="toast-con"></div>`
            })

            // 2、创建实例,挂载到文档以后的地方
            let tpl = new LoadingTip().$mount().$el
            // 3、把创建的实例添加到body中
            document.body.appendChild(tpl);

            setTimeout(function () {
                document.body.removeChild(tpl);
                callback && callback();
            }, timeout);
        },
        UrlEncode: function (data = {}) {
            var datastr = Qs.stringify(data);
            return LZString.compressToBase64(datastr);
        },
        UrlDecode: function (data = "") {
            var datastr = LZString.decompressFromBase64(data);
            return datastr==null?null:Qs.params(datastr);
        }
    }

    Vue.prototype.common = common;


vue 怎么去使用全局Toast 和Confirm

var app = new Vue({
        el: '#app',
        data: {
            reason: '',
        },
        created: function () {
            var that = this;

        },
        methods: {
            submit: function () {
                var that = this;

                that.common.Toast('测试完毕',function(){console.log(‘关闭了’);});
                 that.common.Confirm('提示','确定要删除吗?',function(){console.log(‘关闭了’);});
            },
        }
    });


  • 2019-10-11 13:48:00

    关于Integer比较相等的问题

    原来两个Integer类型的数字不能用==来判断,要用equal 不过Integer类型的可以与1,2这样的纯数字来判断

  • 2019-10-14 21:18:57

    Comparable 的 使用

    要做这个呢,我们也是用到了Arrays.sort 这个排序的方法!但不同的是,我们之前用的是int数组,现在我们用的是这个UserBean数组。如果你想对这个UserBean数组进行排序,你要多做一件事,就是让这个 UserBean类去 实现Comparable 的接口,并重写 里面  comparaTo 的方法。注意,这个接口是可以提供泛型的 ———————————————— 版权声明:本文为CSDN博主「sdn_bt496」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明