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

413
Views
In vuejs, quoting variables in HTML element attribute doesn't work

Here is the code:

<tr v-for="(item, index) in detail" :key="item.name" class="[[ item.name ]]">
  <td>[[ index + 1 ]]</td>
  <td>[[ item.name ]]</td>

The rendered HTML looks like this:

<tr class="[[ item.name ]]">
  <td>1</td>
  <td>Job</td>
</tr>
<tr class="[[ item.name ]]">
  <td>2</td>
  <td>Jesse</td>
</tr>
<tr class="[[ item.name ]]">
  <td>3</td>
  <td>Wazert</td>
</tr>

The class="[[ item.name ]]" just don't change. What I expect is:

<tr class="Job">
  <td>1</td>
  <td>Job</td>
</tr>
<tr class="Jesse">
  <td>2</td>
  <td>Jesse</td>
</tr>
<tr class="Wazert">
  <td>3</td>
  <td>Wazert</td>
</tr>

How should I fix it?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

First thing Square bracket not worked in vue.js you need to use interpolation for binding the data dynamically.

So you need to use like For Example

HTML

<table border="1">
   <tr v-for="(item, index) in detail" :key="item.name" :class="item.name">
      <td>{{ index + 1 }}</td>
      <td>{{ item.name }}</td>
   </tr>
</table>

JS

data: function () {
  return {
    detail: [{ name: "Job" }, { name: "Jesse" }, { name: "Wazert" }],
  };
},

Here you can play with code

over 4 years ago · Santiago Trujillo Report

0

You need to use class-binding and interpolate the data:

new Vue({
  el: "#app",
  data: () => ({ 
    detail: [ { name: "Job" }, { name: "Jesse" }, { name: "Wazert" } ] 
  })
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">
  <table>
    <tr v-for="(item, index) in detail" :key="item.name" :class="item.name">
      <td>{{index + 1}}</td>
      <td>{{item.name}}</td>
    </tr>
  </table>
</div>

over 4 years ago · Santiago Trujillo 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!