Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

257
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda