I am trying to require in api.js, but receiving the error "TypeError: (0 , _typeof3.default) is not a function". Attempting to debug this issue shows that removing "async" word makes the error disappear but I'm trying to use async. I have all the babel async plugins installed, defined in package.json and included in the plugins of webpack.config.js and .babelrc. Please help.
my api.js
let config = require('config'),
$ = require('jquery')
module.exports = {
loggedIn: false,
api: async (endpoint, params={}, method="GET") => {
console.log(endpoint, params, method)
let request,
url = config.urls.api + endpoint
switch(method){
case 'GET': request = $.get(url); break;
case 'POST': request = $.post(url); break;
}
try{
let res = await request
return res
}catch(e){
if(e == 'not logged-in'){
this.loggedIn = false
}
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…