[英]Error while importing component in vuejs
It could be a simple mistake. 这可能是一个简单的错误。 But I'm a newbie in this area. 但是我是这个领域的新手。 I get a Syntax Error on Unexpected Token here: 我在这里收到关于意外令牌的语法错误:
component: () => import('@/layouts/default.vue'),
What would be the issue? 会是什么问题?
If you want to import a component into another module/component then use this at the top of your file: 如果要将组件导入另一个模块/组件,请在文件顶部使用此组件:
import MyComponent from '@/layouts/default.vue'
...assuming you have exported MyComponent as the default export in your default.vue file. ...假设您已将MyComponent导出为default.vue文件中的默认导出。
You can change MyComponent to whatever you want. 您可以将MyComponent更改为所需的任何内容。
I'm assuming you're using stand alone components. 我假设您正在使用独立组件。 In that case, include export default
in your default.vue
file and then import DefaultComponent from '@/layouts/default.vue
at the top of the file. 在这种情况下,请在default.vue
文件中包括export default
,然后import DefaultComponent from '@/layouts/default.vue
文件顶部的import DefaultComponent from '@/layouts/default.vue
中import DefaultComponent from '@/layouts/default.vue
。 Then, include the DefaultComponent in the Components section. 然后,在“组件”部分中包含DefaultComponent。
<template>
<p>{{hi}}</p>
</template>
<script>
export default{
data: function(){
hi: 'Hello World'
}
}
</script>
<style
</style>
<template>
<default-component></default-component>
</template>
<script>
import DefaultComponent from '@layouts/default.vue';
export default{
components: {
'default-component': DefaultComponent
}
}
</script>
<style
</style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.