码迷,mamicode.com
首页 > Web开发 > 详细

vue 自定义js文件 写方法

时间:2019-11-26 13:26:14      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:rom   set   htm   func   ons   div   function   nan   com   

//全局函数方法
exports.install = function(Vue, options) {
    Vue.prototype.$popup = function(msg, time) { 
         //msg 为内容
         //time 弹窗显示时间
          time = isNaN(time) ? 3000 : time;
        var m = document.createElement(‘div‘);
        m.className="popupall"
        m.innerHTML = msg;
        document.body.appendChild(m);
        setTimeout(function () {
            var d = 0.5;
            m.style.webkitTransition = ‘-webkit-transform ‘ + d + ‘s ease-in, opacity ‘ + d + ‘s ease-in‘;
            m.style.opacity = ‘0‘;
            setTimeout(function () {
                document.body.removeChild(m)
            }, d * 1000);
        }, time);
      
    };
};

单页调用

that.$popup("发表内容",3000)

main.js文件引用

import com from ‘./public/js/com‘
Vue.use(com);

 

vue 自定义js文件 写方法

标签:rom   set   htm   func   ons   div   function   nan   com   

原文地址:https://www.cnblogs.com/chen527/p/11934552.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!