Vue.js: Conditional class style binding

后端 未结 5 796
难免孤独
难免孤独 2020-11-28 08:51

I have some data that is accessible via:

{{ content[\'term_goes_here\'] }}

... and this evaluated to either true or fals

5条回答
  •  感情败类
    2020-11-28 09:29

    if you want to apply separate css classes for same element with conditions in Vue.js you can use the below given method.it worked in my scenario.

    html

     

    in here, Main and Sub are two different class names for same div element. v-bind:class directive is used to bind the sub class in here. page is the property we use to update the classes when it's value changed.

    js

    data:{
    page : true;
    }
    

    here we can apply a condition if we needed. so, if the page property becomes true element will go with Main and Sub claases css styles. but if false only Main class css styles will be applied.

提交回复
热议问题