如何在nuxtjs的js文件中访问“ this”?

时间:2020-03-08 00:17:23

标签: vue.js nuxt.js

我使用“ this.toast.error”显示消息。无法访问显示消息的“ this”有问题吗?

HttpService.js:

const http = axios.create(defaultOptions)

http.interceptors.response.use(
  response => {
    const myResponse = { ...response.data }

    if (
      (myResponse.status === 'success' &&
        (myResponse.object === null ||
          (myResponse.object && !myResponse.object.error))) ||
      (myResponse.meta && myResponse.meta.code === 200)
    ) {
      return myResponse.object || myResponse
    }

    return handleError(response)
  },
  error => {
    return this.$toast.error(response, {
      timeout: 2500,
      y: 'top',
      color: 'var(--v-error-base)'
    })
  }
)
export { http }

0 个答案:

没有答案