我正在使用euvl / VUE </跨度> - 对我的申请通知的通知。每次我想通知用户我都需要编写以下代码:
如果在里面 Vue公司 </跨度> 零件:
这一点。$通知({ 小组
进口 Vue公司 </跨度> 从’‘ VUE </跨度> “从’./App.vue’导入应用程序从’./support/notifications’导入通知
Vue.use(通知)
新 Vue公司 </跨度> ({ 渲染:h =&gt; H(APP)})$安装( ‘#应用程序’)
notifications.js锟
我认为你几乎达到了你想要的,除了使用 Object.defineProperty 。 试着回来一个 function 引用而不是 Vue.notify 回归 get 方法。
Object.defineProperty
function
Vue.notify
get
import Vue from 'vue' import Notifications from 'vue-notification' Vue.use(Notifications) export default function install(Vue) { Object.defineProperty(Vue, 'notification', { get() { return notification; } }) Object.defineProperty(Vue.prototype, '$notification', { get() { return notification; } }) } function notification(message) { Vue.notify({ group: 'panel', type: 'success', duration: 5000, text: message }) }