我有多个dis元素,其中有一个基于特殊条件的类.一旦我从数据库收到数据,我就会判断此条件.问题是组件在从数据库接收数据之前被渲染.我try 创建一个Deliverc函数并使用await,但没有起作用.(我对JS和Vue不是很精通)

组件:

<v-table v-if="allActions.length != 0">
  <thead>
    <tr>
      <th class="text-center text-blue" :colspan="lastWeekCount + 1">Недели</th>
    </tr>
    <tr>
      <th class="text-left text-blue">Actions</th>
      <th v-for="week in 15" :key="week" class="text-center text-blue">
        {{ week + firstWeekCount - 1 }}
      </th>
    </tr>
  </thead>
  <tbody>
    <tr v-for="action in allActions" :key="action">
      <td>{{ action.reason }}</td>
      <td v-for="week in 15" :key="week" class="text-center">
        <div>
          <v-dialog max-width="500">
            <template
              v-slot:activator="{
                props: activatorProps,
              }"
            >
              <div
                v-if="checkActionStatus(week + firstWeekCount - 1, action.id)"
                @click="selectChosenAction(week + firstWeekCount - 1, action.id)"
                v-bind="activatorProps"
                :class="checkActionStatus(week + firstWeekCount - 1, action.id)"
                style="height: 15px; width: 15px"
              ></div>
            </template>

            <template v-slot:default="{ isActive }">
              <v-card title="Change a status">
                <v-card-text>
                  <v-select
                    v-model="chosenAction.status"
                    :items="['OK', 'nOK', 'Empty']"
                    label="Status state"
                    :disabled="isStatus"
                    item-title="name"
                    return-object
                    variant="solo"
                  ></v-select>
                  <div v-if="isStatus" class="text-red-lighten-1">
                    Action is already chosen
                  </div>
                </v-card-text>
                <v-card-actions>
                  <v-spacer></v-spacer>
                  <v-btn text="Close" @click="isActive.value = false"></v-btn>
                  <v-btn
                    class="ma-2"
                    color="success"
                    variant="flat"
                    v-bind="props"
                    @click="updateChosenAction"
                    >Save</v-btn
                  >
                </v-card-actions>
              </v-card>
            </template>
          </v-dialog>
        </div>
      </td>
    </tr>
  </tbody>
</v-table>

带有spec await的函数:

const checkActionStatus = async (week, action_id) => {
  try {
    const response = await httpServer.post("selectActionByWeek", { week: week, action: action_id });
    if (response.data[0]) {
      switch (response.data[0].status) {
        case 'Empty':
          return "bg-blue-grey-lighten-3 rounded-circle mx-auto";
        case 'OK':
          return "bg-light-green-accent-3 rounded-circle mx-auto";
        case 'nOK':
          return "bg-amber-lighten-2 rounded-circle mx-auto";
        default:
          return "bg-blue-grey-lighten-3 rounded-circle mx-auto";
      }
    } else {
      return "bg-blue-grey-lighten-3 rounded-circle mx-auto";
    }
  } catch (error) {
    console.log(error);
    return "bg-blue-grey-lighten-3 rounded-circle mx-auto";
  }
};

推荐答案

OP将他的电话转移到了@click,在这other answer上获得一些灵感也有所帮助.

Vue.js相关问答推荐

Vue3多姆参考已安装的添加EventButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButtButt

如何默认打开一个v-list-group?

仅在构建时为 Vue3 和 TailwindCSS 添加前缀

如何使用 async/await 在 vue js 中添加标头

带有参数的 Vuex 映射 Getter - 缓存?

如何在 Nativescript 应用程序中调用 axios/api 调用

VueJS:为什么在input事件处理程序中触发Input输入事件?

Vuelidate 判断true/false

Vuetify 置顶工具栏

如何将Vue的主应用程序渲染到body元素?

包含 Vue.js v-if 和 v-for 指令的 HTML 标签在加载时flash

更新 v-for 中使用的数组内的对象时,Vue js react性问题

包含 Vue 组件的 HTML 字符串的 Nuxt 渲染函数

是否可以从 vue-devtools 中排除 vue 事件和 vuex Mutations?

$set 不是函数

无法访问函数内的数据属性

如何设置 :id 前缀字符串?

带有 Google Auth Signin 的 Vuejs 全局函数

检测 Vue-Router 导航Guards中的后退按钮

使用 vuex-persistedstate 仅使一个模块持久化