You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
663 B

10 months ago
  1. import toast from './index.vue'
  2. export default {
  3. // 注册Toast
  4. install(Vue) {
  5. Vue.prototype.$MyToast = (text, opts) => {
  6. // 设置默认参数,可设置多个
  7. let defaultOpts = {
  8. duration: 2000
  9. }
  10. opts = Object.assign(defaultOpts, opts);
  11. // 生成一个Vue的子类
  12. let toastTpl = Vue.extend(toast);
  13. // 生成一个该子类的实例
  14. let tpl = new toastTpl({
  15. data : opts
  16. }).$mount();
  17. // 并将此div加入全局挂载点内部
  18. document.body.appendChild(tpl.$el);
  19. // 修改提示语
  20. tpl.text = text;
  21. // 定时消失
  22. setTimeout(() => {
  23. document.body.removeChild(tpl.$el);
  24. }, opts.duration)
  25. }
  26. }
  27. }