最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to export multiple objects from a .vue file - Stack Overflow

programmeradmin0浏览0评论

I'm using typescript with Vue. And for this specific use case, I'd like to export multiple items from my .vue file. Like this:

// FooBar.vue

<template>
    ...
</template>

export class Foo extends Vue {
    foo: string = "foo";
}

export const Bar = {bar: "bar"};

And then import them like this:

// Baz.vue

import { Foo, Bar } from 'FooBar.vue';

@Components({ components: { Foo }})
... // rest of the code

Is there a way to export multiple objects from a .vue file in Vue?

I'm using typescript with Vue. And for this specific use case, I'd like to export multiple items from my .vue file. Like this:

// FooBar.vue

<template>
    ...
</template>

export class Foo extends Vue {
    foo: string = "foo";
}

export const Bar = {bar: "bar"};

And then import them like this:

// Baz.vue

import { Foo, Bar } from 'FooBar.vue';

@Components({ components: { Foo }})
... // rest of the code

Is there a way to export multiple objects from a .vue file in Vue?

Share Improve this question edited Sep 26, 2018 at 21:48 Ben Smith 20.2k6 gold badges73 silver badges96 bronze badges asked Sep 26, 2018 at 21:40 Artur GrigioArtur Grigio 5,5539 gold badges48 silver badges66 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 17

In your vue file write:

class Foo extends Vue {
    foo: string = "foo";
}

const Bar = { bar: "bar" };

export { Bar };
export default Foo;

You will then be able to import these using:

import Foo, { Bar } from 'FooBar.vue';

More detailed information on how export works can be found here.

发布评论

评论列表(0)

  1. 暂无评论