Take Vuetify's v-data-table as an example to implement the function of conditionally hiding columns
P粉775723722
P粉775723722 2023-08-25 14:48:06
0
1
453

I have a table with columns v-data-table and actions and I want to display this column only if the user has certain permissions. I'm using a mixin to check permissions.

I tried the following without success:

 

This is how I use the mixin in the component file:

import BaseLayout from "../layouts/Base/Base.vue"; import hasPermission from "../../../mixins/hasPermissions"; export default { mixins: [hasPermission], ... } 

Result: [1]: https://i.stack.imgur.com/aVSgJ.png

P粉775723722
P粉775723722

reply all (1)
P粉681400307

header.actionsis a slot used to overrideactionscolumn header rendering. If you don't pass it (when the condition isfalse), Vuetify will render the default representation.

If you want to conditionally hide (not render) certain columns, define your table header ascomputed

computed: { headers() { const headers = [ // 其他表头定义 ] if(this.hasPermission('update center')) { headers.push({ // actions 表头定义 }) } return headers } }
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!