[Vuejs]-How to export function from composition api vuejs 3

0👍

vue files can’t compile to different code it doesn’t accept export something out of file
maybe you are looking for something like defineExpose

Counter.vue

<template>
  <button @click="counter++">count: {{ counter }}</button>
</template>

<script lang="ts" setup>
const counter = ref(0)

defineExpose({ counter })
</script>

App.vue

<template>
  <Counter ref="counterRef" />

  Count in Counter: {{ counterRef?.counter }}
</template>

<script lang="ts" setup>
const counterRef = ref<InstanceType<typeof Counter>>()
</script>

Leave a comment