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
549
<p>I have a table with columns <code>v-data-table</code> and <code>actions</code> and I want to display this column only if the user has certain permissions. I'm using a mixin to check permissions. </p> <p>I tried the following without success: </p> <pre class="brush:html;toolbar:false;"><template v-slot:[`header.actions`]="{ header }" v-if="hasPermission('update center ')"> {{ header.text }} </template> </pre> <p>This is how I use the mixin in the component file: </p> <pre class="brush:js;toolbar:false;">import BaseLayout from "../layouts/Base/Base.vue"; import hasPermission from "../../../mixins/hasPermissions"; export default { mixins: [hasPermission], ... } </pre> <p>Result: [1]: https://i.stack.imgur.com/aVSgJ.png</p>
P粉775723722
P粉775723722

reply all(1)
P粉681400307

header.actions is a slot used to override actions column header rendering. If you don't pass it (when the condition is false), Vuetify will render the default representation.

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

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