vue中在api.js中调用vux 的toast插件

每次在调用vuxtoast插件的时候  大都是在vue项目的实例中。

main.js

import Vue from 'vue';
import { ToastPlugin } from 'vux'
Vue.use(ToastPlugin)

Vue页面中

export default {    
data () {
      return {}
},
methods: {
      goToast() {
        this.$vux.toast.show({
        type: 'text',
        position: 'middle',
        text: "消息提示!"
      })
    }
  }
}

但当在api.js中调用toast的写法就不是如此了。代码如下:

import Vue from 'vue';
import { ToastPlugin } from 'vux'

Vue.use(ToastPlugin)

let vm = new Vue()

vm.$vux.toast.show({
    type: 'text',
    position: 'middle',
    text: "消息提示!"
})
原文地址:https://www.cnblogs.com/-bingyan/p/8991026.html