支持您有这样的模块文件:
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()
不是函数。这是为什么?显然,我们正在导出具有所有功能的auth
和authService.js
文件中的字符串。
谢谢您的帮助。
我想你想这样做
export const auth = (loginMethod === 'popup')
? { loginMethod, ...authPopup }
: { loginMethod, ...authRedirect };
以便导出的auth
对象实际上将包含来自各自导入的名称空间对象的所有方法。