简体   繁体   中英

Vue 3 - Emit in reusable / composable file

I want to use emit in my following file: useGoo.ts

import Swal from "sweetalert2/dist/sweetalert2.js";

export default function useModal() {

  const { emit } = getCurrentInstance();

  function myId() {
    emit('id', '123')
  }

}

But the emit does not work ofcourse. Can't get it working. Error:

Property 'emit' does not exist on type 'ComponentInternalInstance | null'

As I'm using TypeScript. The solution is as following: const { emit } = getCurrentInstance() as any;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM