如何根据 json 数据设置动态 class 名称?

How to set dynamic class name from json data?

我想动态设置 css class 名称 例如:

{ "id": "00053", "cssLevel": "53", "username": "user53", "Title": "title53"}
{ "id": "00054", "cssLevel": "54", "username": "user54", "Title": "title54"}

and then

<div class="{{cssLevel}}">{{model.username}}</div>

or

<div v-bind:class="cssLevel">{{model.username}}</div>

根据你的问题,我希望你的数据在 model

<div v-bind:class="model.cssLevel">{{model.username}}</div>

<div :class="model.cssLevel">{{model.username}}</div>

两者都应该适合您。您忘记在此处访问模型(cssLevel 与用户名相同)