Vue 单文件组件(.vue 文件)必须“默认导出”还是可以使用命名导出?
Do Vue single file components (.vue files) have to `export default` or can they use named exports?
export default
似乎是一种过时且不鼓励的导出模块的方式。
例如:
- https://blog.neufund.org/why-we-have-banned-default-exports-and-you-should-do-the-same-d51fdc2cf2ad
- https://basarat.gitbook.io/typescript/main-1/defaultisbad
然而,当我从这里更改我所有的 Vue 组件时:
<script lang="ts">
'use strict';
import {store} from '../../data/store';
const c = { 'data': store };
export default c; // <-- HERE
</script>
至此
<script lang="ts">
'use strict';
import {store} from '../../data/store';
const c = { 'data': store };
export {c as headerBar}; // <-- HERE
</script>
我在浏览器中得到 dateWidget.vue:6 Uncaught TypeError: Cannot set property 'render' of undefine
。
为什么会发生这种情况,有什么方法可以通过 Vue 和 Typescript 使用正确的现代导出吗?
这实际上是在 Vue SFC spec 本身中定义的,所以我认为没有办法解决它..
The default export should be a Vue.js component options object. Exporting an extended constructor created by Vue.extend()
is also supported, but a plain object is preferred.
export default
似乎是一种过时且不鼓励的导出模块的方式。
例如:
- https://blog.neufund.org/why-we-have-banned-default-exports-and-you-should-do-the-same-d51fdc2cf2ad
- https://basarat.gitbook.io/typescript/main-1/defaultisbad
然而,当我从这里更改我所有的 Vue 组件时:
<script lang="ts">
'use strict';
import {store} from '../../data/store';
const c = { 'data': store };
export default c; // <-- HERE
</script>
至此
<script lang="ts">
'use strict';
import {store} from '../../data/store';
const c = { 'data': store };
export {c as headerBar}; // <-- HERE
</script>
我在浏览器中得到 dateWidget.vue:6 Uncaught TypeError: Cannot set property 'render' of undefine
。
为什么会发生这种情况,有什么方法可以通过 Vue 和 Typescript 使用正确的现代导出吗?
这实际上是在 Vue SFC spec 本身中定义的,所以我认为没有办法解决它..
The default export should be a Vue.js component options object. Exporting an extended constructor created by
Vue.extend()
is also supported, but a plain object is preferred.