【发布时间】:2019-06-26 15:15:49
【问题描述】:
我想根据用户是否为 isAdmin 显示/隐藏表列“first_name”。
这是我的桌子:
<b-table
striped
hover
small
stacked="sm"
selectable
select-mode="single"
show-empty
:items="allProducts"
:fields="productsFieldsForBTable"
:busy="isLoading"
primary-key="id"
>
<template slot="actions" slot-scope="data">
<select v-model="data.selected">
<option v-for="user in users" :key="user.id" :value="user.id">{{user.first_name}}</option>
</select>
</template>
</b-table>
这是商店吸气剂中的 productsFieldsForBTable。
productsFieldsForBTable: () => {
return [
{
key: 'product_name',
sortable: true,
},
{
key: 'buying_price',
sortable: true,
},
{
key: 'notes',
sortable: true,
},
{
key: 'first_name',
label: 'User',
sortable: true,
},
// A virtual column for additional action buttons
{ key: 'actions', label: 'Actions' }
]
}
存储 getter 具有 isAdmin 标志,用于隐藏/显示列
我不确定要使用什么语法以及在哪里检查条件? (在 b-table 标记中还是在计算中?)
更新 -
如何从商店本身访问 isAdmin 值?它在 getter 中如下所示:
吸气剂:{ isAdmin: (state, getters) => { return getters.isLoggedIn && state.user.role === 'Admin' }, ....
if(getter.isAdmin){ // how to access getters' isAdmin here? // this.$store.getters.isAdmin is not working here.
fields.push({
key: 'first_name',
label: 'User',
sortable: true
})
}
【问题讨论】: