Take Vuetify's v-data-table as an example to implement the function of conditionally hiding columns
P粉775723722
2023-08-25 14:48:06
<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>
header.actions
is a slot used to overrideactions
column 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 as
computed