vuejs3vue-composition-apiemit

emit in fuction in vue 3 composition api


I have a timer, and a function by which the timer stops. I want to use emit in a function, it doesn't work.

 const stopTimer = () => {
  clearInterval(timer.value);

  const emit = defineEmits(["end"]);
  emit("end", reactionTime.value);
};

Solution

  • defineEmits should be called top-level in <script setup> and not inside any arrow function.