在模块中找不到功能

问题描述 投票:0回答:1

支持您有这样的模块文件:

authService.js

import { Screen } from 'quasar'
import * as authPopup from 'src/services/auth/authPopup'
import * as authRedirect from 'src/services/auth/authRedirect'

const loginMethod = Screen.lt.sm ? 'redirect' : 'popup'

export const auth = (loginMethod === 'popup')
  ? { loginMethod, authPopup }
  : { loginMethod, authRedirect }

如果可以这样食用的话,那就太好了:

consumer.js

import { auth } from 'src/services/auth/authService'

const getProfile = () => {
  if (!auth.getAccount()) { return Promise.reject(new Error('no logged on user')) }

  console.log('loginMethod ', auth.loginMethod)
}

但是错误地指出auth.getAccount()不是函数。这是为什么?显然,我们正在导出具有所有功能的authauthService.js文件中的字符串。

谢谢您的帮助。

javascript module
1个回答
1
投票

我想你想这样做

export const auth = (loginMethod === 'popup')
  ? { loginMethod, ...authPopup }
  : { loginMethod, ...authRedirect };

以便导出的auth对象实际上将包含来自各自导入的名称空间对象的所有方法。

© www.soinside.com 2019 - 2024. All rights reserved.