![](/img/trans.png)
[英]How to export and import multiple objects from the same file with JavaScript?
[英]How to export multiple objects from a .vue file
我在Vue中使用typescript
。 對於此特定用例,我想從.vue
文件中導出多個項目。 像這樣:
// FooBar.vue
<template>
...
</template>
export class Foo extends Vue {
foo: string = "foo";
}
export const Bar = {bar: "bar"};
然后像這樣導入它們:
// Baz.vue
import { Foo, Bar } from 'FooBar.vue';
@Components({ components: { Foo }})
... // rest of the code
有沒有一種方法可以從Vue中的.vue
文件導出多個對象?
在您的vue文件中輸入:
class Foo extends Vue {
foo: string = "foo";
}
const Bar = { bar: "bar" };
export { Bar };
export default Foo;
然后,您將可以使用以下命令導入這些文件:
import Foo, { Bar } from 'FooBar.vue';
有關導出工作原理的更多詳細信息,請參見此處 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.