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

155
Views
Vue class binding attribute and multiple tailwind classes

I'm trying to bind an attribute and multiple tailwind classes to an html element. This is for a tab menu, so the idea is that for the "active" tab I take the title dynamically and inject also some tailwind classes to change the look and feel of the "active" tabs.

        <li
            :class="{
                selected: title === selectedTitle,
                selected ? ['border-b-2', 'border-blue-700' ]
            }"
            @click.stop.prevent="selectedTitle = title"
            v-for="title in tabTitles"
            :key="title"
            role="presentation"
        >

At the moment the previous code is not working for me.

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

0

Try like following:

new Vue({
  el: "#demo",
  data() {
    return {
      tabTitles: ['aaa', 'bbb', 'ccc'],
      selectedTitle: ''
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" integrity="sha512-wnea99uKIC3TJF7v4eKk4Y+lMz2Mklv18+r4na2Gn1abDRPPOeef95xTzdwGD9e6zXJBteMIhZ1+68QC5byJZw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div id="demo">
  <li :class=" selectedTitle === title ? 'border-b-2 border-blue-700' : '' "
      @click.stop.prevent="selectedTitle = title"
      v-for="title in tabTitles"
      :key="title"
      role="presentation"
  >{{title}}</li>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

From my point of view following line can't work:

selected ? ['border-b-2', 'border-blue-700' ]

This is a short if else without an else case - I think you ment writing something like this:

<li :class="{
  'selected border-b-2 border-blue-700': title === selectedTitle,
}">
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!