Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

vue.js - How Can I Add my Custom Classes To a Dynamically Class in Vue JS

I want to add a dynamically class to my class List when I used :class I receive a parcing error: Unexpected token font.

<h1 class="flex-auto text-xl font-semibold text-gray-800 player-name <!--dynamic class here-->">
       {{player.name}}
</h1>
<h4 class="text-xl font-semibold text-gray-500 player-team">
      {{player.team}}
</h4>





question from:https://stackoverflow.com/questions/65900535/how-can-i-add-my-custom-classes-to-a-dynamically-class-in-vue-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can pass an object with the keys being the classes and the value being true or false to enable/disable it.

<h1 :class="{'flex-auto text-xl font-semibold text-gray-800 player-name': true 'dynamic': someDataProperty}">
       {{player.name}}
</h1>

I set the classes you had normally to the boolean literal 'true' so they are always enabled, and I set the dynamic property to a data property which should be a boolean.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...