admin管理员组文章数量:1291940
I have a folder like this.
VueTree
ponents
Classic.vue
Modern.vue
index.js
Classic and Modern are simple ponents with template
, export default {}
and a style
.
I am calling both inside index.js
as:
import Classic from './ponents/Classic.vue'
import Modern from './ponents/Modern.vue'
const VueTree= {
Classic ,
Modern
}
export default VueTree
So, when I import this module as:
import {Classic , Modern } from '../../modules/VueTree/index.js'
I get this error
Unknown custom element: - did you register the ponent correctly? For recursive ponents, make sure to provide the "name" option.
I have name: "Classic"
inside my ponents and I am including the in the current file using ponents: { Classic },
but I get the same error.
It only works if I export only one ponent as:
import Classic from './ponents/Classic.vue'
import Modern from './ponents/Modern.vue'
export default Classic
this will work and include the classic, but I can't export both of them like seen in this example .js
I have a folder like this.
VueTree
ponents
Classic.vue
Modern.vue
index.js
Classic and Modern are simple ponents with template
, export default {}
and a style
.
I am calling both inside index.js
as:
import Classic from './ponents/Classic.vue'
import Modern from './ponents/Modern.vue'
const VueTree= {
Classic ,
Modern
}
export default VueTree
So, when I import this module as:
import {Classic , Modern } from '../../modules/VueTree/index.js'
I get this error
Unknown custom element: - did you register the ponent correctly? For recursive ponents, make sure to provide the "name" option.
I have name: "Classic"
inside my ponents and I am including the in the current file using ponents: { Classic },
but I get the same error.
It only works if I export only one ponent as:
import Classic from './ponents/Classic.vue'
import Modern from './ponents/Modern.vue'
export default Classic
this will work and include the classic, but I can't export both of them like seen in this example https://github./greyby/vue-spinner/blob/master/src/index.js
Share Improve this question edited Dec 22, 2017 at 8:54 hidar asked Dec 14, 2017 at 9:54 hidarhidar 5,93916 gold badges49 silver badges75 bronze badges4 Answers
Reset to default 6 +50You need to use export
for named exports, not export default
:
import Classic from './ponents/Classic.vue'
import Modern from './ponents/Modern.vue'
export {
Classic ,
Modern
}
See: https://developer.mozilla/en-US/docs/web/javascript/reference/statements/export
The setup you have is fine.
import Classic from './ponents/Classic.vue'
import Modern from './ponents/Modern.vue'
const VueTree = {
Classic,
Modern
}
export VueTree
The problem is your ponents. I can see you're using a Treeview so, it is a recursive ponent. You should be extra careful about how you create them because it can create a infinite loop.
Take a look at my github for a example on how your VueTree
should work.
Ps: Don't forget to add a key and a name to a recursive ponent.
Components can recursively invoke themselves in their own template. However, they can only do so with the
name
option. Vue Docs.
If what i said does not work. Feel free to send me a github link to the issue and i will be happy to help.
Another way
index.js
export { default as Classic } from './ponents/Classic.vue'
export { default as Modern } from './ponents/Modern.vue'
Modern.vue
import { Classic } from './ponents/index';
export default {
ponents: { Classic }
}
NOTICE: Chlidren ponent must by exported just BEFORE parent ponent in index.js.
I think it's better to do this
本文标签: javascriptUnable to importexport vuejs componentsStack Overflow
版权声明:本文标题:javascript - Unable to importexport vuejs components - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741541327a2384338.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论