最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Changing CSS classes dynamically with vue js - Stack Overflow

programmeradmin0浏览0评论

I have been using vue for about a month now but one thing that I haven't really been able to do properly yet is this.

so in twig we can do something like this

<th class=" 
  {% if condition %}
      class1
  {% else %}      
      class2
  {% end if %}  
">

<th class="sorting_asc" v-for="col in columns" v-if="col.label == sortKey">
<th class="sorting" v-for="col in columns" v-else>

So my first issue is I can't seem to be able to achieve something similar in Vue js. And secondly where I've written 'v-if="col.label == sortKey"', Can I even access the car col.label outside of the html block (outside the loop). Thank you in advanced

I have been using vue for about a month now but one thing that I haven't really been able to do properly yet is this.

so in twig we can do something like this

<th class=" 
  {% if condition %}
      class1
  {% else %}      
      class2
  {% end if %}  
">

<th class="sorting_asc" v-for="col in columns" v-if="col.label == sortKey">
<th class="sorting" v-for="col in columns" v-else>

So my first issue is I can't seem to be able to achieve something similar in Vue js. And secondly where I've written 'v-if="col.label == sortKey"', Can I even access the car col.label outside of the html block (outside the loop). Thank you in advanced

Share Improve this question edited Dec 30, 2016 at 6:18 Saurabh 73.6k44 gold badges190 silver badges251 bronze badges asked Dec 30, 2016 at 5:05 TheMan68TheMan68 1,4697 gold badges28 silver badges52 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 15

You can do following with vuejs with dynamic styling:

<th v-bind:class="{'class1': condition, 'class2': !condition}">

From documentation:

<div v-bind:class="{ active: isActive }"></div>

The above syntax means the presence of the active class will be determined by the truthiness of the data property isActive. you can as well put simple conditions returning boolean in place of isActive

发布评论

评论列表(0)

  1. 暂无评论