我正在使用vuatefy-dialog@nuxt。我想使用警报组件作为导出的方法:

nuxt.config.js配置:

['vuetify-dialog/nuxt', { property: '$dialog' }]

/utils/notification.js文件:

const showNotification = (aMsg, aIsError) => {
  if (!aIsError) {
    this.$dialog.message.success(aMsg, {
      position: "bottom-left",
      icon: "mdi-alert-circle-outline",
      border: "left",
    });
  } else {
    this.$dialog.message.error(aMsg, {
      position: "bottom-left",
      icon: "mdi-alert-circle-outline",
      border: "left",
    });
  }
}

export default showNotification;

调用:

showNotification(response.data.message, false);

显示错误:

image.png

2020-10-15 18:10创建
共1个回答
EC
游客ecqXMk

调用时未指定this,默认是window,而window没有$dialog属性,你可以这样使用:

showNotification.call(this, response.data.message, false)

或者

const showNotificationWrap = showNotification.bind(this);
showNotificationWrap(response.data.message, false)