admin管理员组文章数量:1208155
I'm returning a Promise
from this function
const liab_config = () => {
return axios.get(`${config.server_url}/fetch_config_liab`);
}
export default { liab_config }
And trying to handle the Promise
inside another file
import liab_config from './utils/kc-adapter'
function set_liab_config(){
liab_config().then((response) => {
if(response.data.success){
let { kc_config_liab } = response.data;
return kc_config_liab['auth-server-url'];
}
else
return null;
}).catch(ex =>
console.log(ex));
}
Here I'm getting the error as:
Uncaught TypeError: Object(...) is not a function
on line liab_config().then((response)
. What could be the reason?
I'm returning a Promise
from this function
const liab_config = () => {
return axios.get(`${config.server_url}/fetch_config_liab`);
}
export default { liab_config }
And trying to handle the Promise
inside another file
import liab_config from './utils/kc-adapter'
function set_liab_config(){
liab_config().then((response) => {
if(response.data.success){
let { kc_config_liab } = response.data;
return kc_config_liab['auth-server-url'];
}
else
return null;
}).catch(ex =>
console.log(ex));
}
Here I'm getting the error as:
Uncaught TypeError: Object(...) is not a function
on line liab_config().then((response)
. What could be the reason?
2 Answers
Reset to default 10You're default-exporting an object literal. You want to use either a named export
const liab_config = …;
export { liab_config as liab_config }
// shorter:
const liab_config = …;
export { liab_config }
// or just:
export const liab_config = …;
with
import { liab_config } from './utils/kc-adapter'
or a default export
const liab_config = …;
export { liab_config as default }
// or just:
default export const liab_config = …;
// or without the local name:
default export …;
with
import liab_config from './utils/kc-adapter'
When you are accessing something like this
import liab_config from './utils/kc-adapter'
It means you are asking for the default export which must be written like
const liab_config = () => {
return axios.get(`${config.server_url}/fetch_config_liab`);
}
export { liab_config as default };
or like this
const liab_config = () => {
return axios.get(`${config.server_url}/fetch_config_liab`);
}
export default liab_config;
And if you don't want to make it default then pass it like
export const liab_config = () => {
return axios.get(`${config.server_url}/fetch_config_liab`);
}
or
const liab_config = () => {
return axios.get(`${config.server_url}/fetch_config_liab`);
}
export { liab_config };
And access it like
import {liab_config} from './utils/kc-adapter'
本文标签: javascriptES6 Uncaught TypeError Object() is not a functionStack Overflow
版权声明:本文标题:javascript - ES6 Uncaught TypeError: Object(...) is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738728110a2109156.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
export default liab_config
– Yury Tarabanko Commented Jul 17, 2018 at 6:38import {liab_config} from './utils/kc-adapter'
– Tan Duong Commented Jul 17, 2018 at 6:39export default { liab_config }
. – Tan Duong Commented Jul 17, 2018 at 6:46