toast vuejs

components - toast - src - toast.vue





components - toast - index.js

import Vue from 'vue'
import Toast from './src/toast'

export default {
  install(Vue, defaultOptions = {}) {
    const CONSTRUCTOR = Vue.extend(Toast)
    const CACHE = {}
    Object.assign(Toast.DEFAULT_OPT, defaultOptions)

    function toast(msg, options = {}) {
      options.message = msg
      let toast = CACHE[options.id] || (CACHE[options.id] = new CONSTRUCTOR)
      if (!toast.$el) {
        let vm = toast.$mount()
        document.body.appendChild(vm.$el)
      }
      toast.queue.push(options)
    }
    Vue.toast = Vue.prototype.$toast = toast
  }
}

app.js

import Toast from './components/toast/'
Vue.use(Toast)

this.$toast("请输入您的姓名");

你可能感兴趣的:(toast vuejs)