Мой одностраничный файл компонента:
<template>
<div></div>
</template>
<style lang = "scss" scoped>
</style>
<script lang = "ts">
export const component = Vue.extend({...});//This is my component.
export let foo = 'bar'; //Other vars I want to export.
</script>
Где я хочу импортировать компонент:
import * as myComp from './path_to_file_above';//Import the file above
Vue.extend({
components:{
myComp:myComp.component;//Register the component exported.
},
mounted(){
console.info(myComp.foo);//Use other vars exported.
}
})
Получил ошибку:
Uncaught TypeError: Cannot set property 'render' of undefined
at normalizeComponent (componentNormalizer.js?2877:24)
at eval (PageEditor.vue?e50e:9)
at Module../src/components/PageEditor.vue (app.js:7568)
at __webpack_require__ (app.js:724)
at fn (app.js:101)
at eval (cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/ts-loader/index.js?!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/Designer.vue?vue&type=script&lang=ts&:36)
at Module../node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/ts-loader/index.js?!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/Designer.vue?vue&type=script&lang=ts& (app.js:2736)
Поддерживает ли одностраничный компонент модуль экспорта нескольких частей? Если нет, то как мне экспортировать другую информацию о компоненте?
Просто экспортируйте компонент по умолчанию и экспортируйте другие переменные с другими именами и зарегистрируйте компонент с помощью myComp.default
:
export default Vue.extend({
//my component
})
export let foo = 'bar'//other vars
import * as myComp from './path_to_file_above';
Vue.extend({
components:{myComp:myComp.default},
mounted(){console.info(myComp.foo)}
})