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

156
Views
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 answers
Answer question

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 Report
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!