import './index.styl'
export default ()=>{
  let req = 0;
  return {
    install:function(Vue){
      Vue.prototype.$mytoast = function (options) {
        let opt = {
          message:'成功',
          duration:2000
        }
        for (var key in options){
          if(options.hasOwnProperty(key)){
            opt[key] = options[key];
          }
        }
        if(!document.querySelector('div.vue-toast')){
          creatEle(opt);
        }
      }
    }
  }
}
function creatEle(opt) {
  let ele = document.createElement('div');
  ele.className = 'vue-toast';
  ele.innerHTML = `<span class="vue-tip fadeIn">${opt.message}</span>`;
  document.body.appendChild(ele);
  setTimeout(()=>{
    removeEle(ele);
  },opt.duration);
  ele.addEventListener("touchmove", function(e) {
    e.stopPropagation();
    e.preventDefault();
  })
}
function removeEle(ele) {
  if(ele){
    document.body.removeChild(ele);
  }
}