javascript - js import 一个对象同时解构 出现undefined
本文介绍了javascript - js import 一个对象同时解构 出现undefined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
a.js
let test = function() {
}
export default {
test
}
b.js
import { test } from 'a.js'
console.log(test) // undefined
import all from 'a.js'
console.log(all) // {test: f}
解决方案
export default test 就可以了
a.js
let test = function() {
}
export default test
b.js
import test from 'a.js'
console.log(test) // undefined
或者
export const test = function () {}
import {test} from 'a.js'
这篇关于javascript - js import 一个对象同时解构 出现undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文