vue.js - VueJS 动态图标类
问题描述
我有以下i
元素:
<i class="icon-user custom-style test"
v-if="employee.status === 0 && this.employeeType === 'admin'">
</i>
我想根据v-if
相同的条件替换类图标用户。
所以,如果employee.status === 0 && this.employeeType === 'admin'
图标类应该是icon-user
,否则它应该是icon-home
有什么线索吗?
解决方案
computed: {
classObject: function() {
if(this.employee.status === 0 && this.employeeType === 'admin')
{
return "icon-user";
}
else return "icon-home"
<i v-bind:class="classObject"></i>
这应该是一个解决方案,文档中有很多其他选项。