我正在尝试根据propertys(overallStatus)值向表行添加bootstrap类(成功,减弱...)。
我如何在下面的代码中实现这个功能?
提前致谢!
<div id="people" class="col-md-12">
<v-client-table :data="tableData" :columns="columns" :options="options"></v-client-table>
</div>
Vue.use(VueTables.client, {
perPage: 50,
skin: 'table table-condensed'
});
new Vue({
el: "#people",
ready: function () { },
methods: {},
data: {
columns: ['deviceType', 'reasonForStatus', 'ip', 'monitorIsOn', 'freeSpace', 'cpuUsage', 'availableRam', 'statusTime'],
options: {
dateColumns: ['statusTime'],
headings: {
deviceType: 'Device Type',
ip: 'Device Ip',
reasonForStatus: 'ReasonForStatus',
freeSpace: 'Free Space',
cpuUsage: 'CPU Usage',
availableRam: 'Available Ram',
statusTime: 'Log Time'
},
templates: {
deviceType: function (row) {
return row == 0 ? "Stander" : "Monitor";
},
availableRam: function (row) {
return row.availableRam + " mb.";
},
freeSpace: function (row) {
return row.freeSpace + " %";
},
cpuUsage: function (row) {
return row.cpuUsage + " %";
},
},
},
selectedLetter: '',
tableData: tableItems,
}
});
答案 0 :(得分:4)
您需要使用v-bind:class
指令(或更短版本:class
)。看看docs here。
示例:
data: function () {
return: {
error: true,
errorType: 'alert-error'
}
}
<template>
<div class="alert" :class="{ errorType: error }"</div>
</template>
<!-- or static text assignment -->
<template>
<div class="alert" :class="{ 'alert-error': error }"</div>
</template>
这两者都会导致
<div class="alert alert-error"></div>
要同时绑定多个类,您可以这样做:
<template>
<div :class="{ 'class1 class2 class3': error }"</div>
</template>
或
<template>
<div :class="['class1', 'class2', error ? 'class3' : 'class4']"></div>
</template>