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

159
Vistas
How to assign HTML code to a variable in Vue.js

I would like to include some HTML in a variable within my Vue.js 3 setup() function to use later within the template.

When I try the following, I get an error of "VueCompilerError: Invalid end tag." because Vue seems to think it is part of the component's code (which of course it is not).

<script>
imports...

setup() {

const a = a;
const b = b;

const MyHTML = '<script></script>'  // Vue thinks the </script> tag is part of the code
}
</script> // This gets thrown an error of VueCompilerError: Invalid end tag.

How can I then store HTML as a string within a variable without it being interpreted by Vue?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I search about that and find several solutions. one of the solutions is below the line. and I think this is the best solution

<div v-html="MyHTML"></div>  
// eslint-disable-next-line no-useless-escape
const MyHTML = ref('<script><\/script>')

another funny solution is

const MyHTML = '...... </scr'+'ipt>......';
about 4 years ago · Juan Pablo Isaza Denunciar
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