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

236
Views
How to add variables in vue and use them as a code editor?

I am building a code editor in vue, which has 4 main parts: the html-code, the css-code, the js-code and the result (preview). I want to add variables from the data (html code, css code and js code) so I can use the added data for the result in the code editor.

My template looks like this:

<template>
  <div class="grid">
    <div id="html" class="grid-cell">
      <textarea v-model="htmlCode" name="" id="" cols="30" rows="10"></textarea>
      <div class="title">This is a cell</div>
    </div>
    <div id="css" class="grid-cell">
      <textarea v-model="cssCode" name="" id="" cols="30" rows="10"></textarea>
      <div class="title">This is a cell</div>
    </div>
    <div id="js" class="grid-cell">
      <textarea v-model="jsCode" name="" id="" cols="30" rows="10"></textarea>
      <div class="title">This is a cell</div>
    </div>
    <div id="preview" class="grid-cell">
      <div v-html="htmlandcss"></div>
      <div class="title">This is a cell</div>
    </div>
  </div>
</template>

And my script looks like this:

<script>
export default {
  name: "CodeEditor",
  methods: {},
  data() {
    return {
      htmlCode: '<h1>hi</h1>',
      cssCode: '',
      jsCode: '',
      htmlandcss: this.htmlCode + this.cssCode
    }
  },[![this is ][1]][1]
  computed: {
  }
};
</script>

My result in the code editor itself should look like an h1.

This is my result for now:

https://i.stack.imgur.com/J25qW.png

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Make your result-variable a computed property and the problem is gone:

<script>
export default {
  name: "CodeEditor",
  methods: {},
  data() {
    return {
      htmlCode: '<h1>hi</h1>',
      cssCode: '',
      jsCode: '',
    }
  },
  computed: {
    htmlandcss() {
      return this.htmlCode.concat(this.cssCode);
  }
};
</script>
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!