Subscribe on changes!

Add a context=module to script tag to export variables from .vue files

avatar
May 21st 2023

What problem does this feature solve?

Hey! Discovering Svelte and getting into its features reminded me of one problem of Vue components: data from them cannot be exported and used anywhere else. Lets say you have a type that is semantically bound to component and its' child props, but for exporting it and reusing them in both you must either have it in some distant faraway types/type.types.ts file or make a file near a Vue component to share it. Svelte resolves this issue (look below)

What does the proposed API look like?

What does the proposed API look like?

<script context="module">
  export const fruits = ['banana', 'apple', 'orange']
</script>

This can be imported in other components and reused there:

<script>
    import {fruits} from './components/Fruits.svelte'

    console.log('Fruits:', fruits)
</script>

While this is a very unimportant feature, it would be nice to see it in Vue :)

avatar
May 22nd 2023

yo can use defineExpose