Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

263
Vistas
Vuejs - Is it possible to convert an living instance back to template?

Is it possible to convert a living component instance back to a template?

Currently, I am working on a form-making website with element-ui and Vue.js. I have finished the <preview /> component. It will present the editing result to the user, and now I need to export the whole result form as a Vue.js template.

Since the resulting form is simply made up of a whole bunch of element-ui form input components, like <el-input>, <el-button>, it might be possible to convert this component back to template. But soon I realized it is not as simple as I thought. I tried doing this by traversing the virtual dom tree but ended up discovering that Vue.js doesn't offer a public API for traversing vnodes. There is an instance attribute named $vnode, but it is the the placeholder node for the component in parent's render tree, according to the code comment. Besides, its children property is undefined. This means I cannot access the children vnodes, thus it becomes impossible to traverse the virtual DOM tree.

Another way is to use the private property _vnode, it is a feasible way though, but the property is private and I'd rather not touch it unless I have no other way.

Another problem I realized later, is that the vdom tree doesn't keep the information about v-if. Once the current true branch is in the virtual DOM tree, and I cannot get other false/invisible tags from the vdom tree.

So it looks like traversing the DOM tree cannot convert an instance back to a template (or maybe I am wrong). Is it some other way that can accomplish my goal?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda