如果 if 语句为真,则在 Vue.js 中隐藏选项卡

Hiding tab in Vue.js if if-statement is true

我有一个 Vue 组件,它有一个如下所示的模板:

<template>
  <div>
    <div class="row" >
      <button class="btn btn-primary" style="margin-bottom:20px" @click="changeSelectedComp">Back</button>
      <button class="btn btn-primary" style="margin-left:1000px" @click="EditMode">Edit</button>
    </div>

    <vue-tabs>
      <v-tab title="Basic">
        <app-players></app-players>
      </v-tab>
      <v-tab title="History">
        <app-histories></app-histories>
      </v-tab>
      <v-tab title="Timetable">
        <app-timetables></app-timetables>
      </v-tab>
      <v-tab title="Scholarship">
        <app-scholarship></app-scholarship>
      </v-tab>
    </vue-tabs>
  </div>
</template>

我想要实现的是隐藏选项卡 HistoryTimetableScholarship 如果此语句为真:

IsCurrentUserMemberOfGroup("Admins", function (isCurrentUserInGroup) {
    if(isCurrentUserInGroup) {
        // hide the tabs
    }
});

这是IsCurrentUserMemberOfGroup函数:

function IsCurrentUserMemberOfGroup(groupName, OnComplete) {

    var currentContext = new SP.ClientContext.get_current();
    var currentWeb = currentContext.get_web();

    var currentUser = currentContext.get_web().get_currentUser();
    currentContext.load(currentUser);

    var allGroups = currentWeb.get_siteGroups();
    currentContext.load(allGroups);

    var group = allGroups.getByName(groupName);
    currentContext.load(group);

    var groupUsers = group.get_users();
    currentContext.load(groupUsers);

    currentContext.executeQueryAsync(OnSuccess,OnFailure);

    function OnSuccess(sender, args) {
        var userInGroup = false;
        var groupUserEnumerator = groupUsers.getEnumerator();
        while (groupUserEnumerator.moveNext()) {
            var groupUser = groupUserEnumerator.get_current();
            if (groupUser.get_id() == currentUser.get_id()) {
                userInGroup = true;
                break;
            }
        }
        OnComplete(userInGroup);
    }

    function OnFailure(sender, args) {
        OnComplete(false);
    }
}

我看了v-if(条件渲染),但没看懂语法。 试过 <vue-tabs v-if="IsCurrentMemberofGroup">,但没用。

如果 if 语句为真,如何隐藏选项卡? (这里是full component

isCurrentUserInGroup放在数据里面,方便大家参考:

export default {
        components: {
            ...
        },
        methods: {
            ...
        },
        data: {
            isCurrentUserInGroup: false
        }
    };

并根据需要将其设置为 true 或 false。 然后您可以在选项卡中将其与 v-if 一起使用:

<vue-tabs>
      <v-tab title="Basic">
        <app-players></app-players>
      </v-tab>
      <v-tab v-if="isCurrentUserInGroup" title="History">
        <app-histories></app-histories>
      </v-tab>
      <v-tab v-if="isCurrentUserInGroup" title="Timetable">
        <app-timetables></app-timetables>
      </v-tab>
      <v-tab v-if="isCurrentUserInGroup" title="Scholarship">
        <app-scholarship></app-scholarship>
      </v-tab>
    </vue-tabs>