Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
Cómo extender la propiedad de ComponentPublicInstance proporcionada por Vue 3 en un determinado archivo vue

Quiero agregar una propiedad personalizada a ComponentPublicInstance. Ejemplo, tengo un archivo Vue. Está usando la API de composición de Vue 3 con <script setup lang='ts'> y declaré una función, como esta:

 <script setup lang='ts'> function close() { console.log("It will be closed") } </script>

Rediné este archivo mediante el render proporcionado por vue, y esto es parte de mi código:

 export const Notification = function (options: Options){ const container = document.createElement('div') const vnode = h(notification, {...options}) // The Render contribute to make vnode processing diff and patch and then mounted on the Container render(vnode, container) const instance = vnode.component?.proxy addIntance(vnode.component as ComponentInternalInstance) console.log("vnode.component", vnode.component) return instance } as NotificationProperty

Hay un Array llamado instanceList que guarda la instancia de Notificación, y quiero llamar al close en la instancia, y recibí un error Property 'close' does not exist on type 'ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>>'. . Este es mi código:

 Notification.closeAll = function () { instanceList.forEach((instance: ComponentInternalInstance, index: number) => { instance.proxy?.close() // There is an error. instanceList.splice(1, index) }) }

He intentado usar los siguientes métodos.

  1. usando defineExpose para exportar la función de close .
  2. para declarar un módulo en shims-vue.d.ts
 declare module "./components/notification/Notification.vue" { interface ComponentCustomProperties { close: () => any; } }

o

 declare module "@vue/runtime-core" { interface ComponentCustomProperties { close: () => any; } }

Ambos no están funcionando.

Ahora, no tengo idea de cómo lidiar con el problema. Gracias por tu ayuda.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!