首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VueJS 3更改单击容器的背景

VueJS 3更改单击容器的背景
EN

Stack Overflow用户
提问于 2022-03-31 07:49:27
回答 1查看 109关注 0票数 0

下面是我的代码,我想改变背景和文本的颜色点击容器,有一个顺风类为h-36。有人能帮我想出解决这个问题的办法吗?

代码语言:javascript
复制
    <template>
    <div>
        <SideBar />
        <NavBar />
        <div class="mt-20 ml-24 mr-2 mb-2 bg-white h-screen flex">
                    <div class="flex w-1/3 flex-col divide-y overflow-auto">
      <div class="h-20 text-black bg-white flex shadow-sm text-lg uppercase font-black w-full items-center px-4">
        <span>Configurations</span>
      </div>
      <div class="overflow-y-scroll">
      <div class="h-36 w-full bg-yellow-650 px-4 flex items-center cursor-pointer">
        <DesktopComputerIcon class="text-white h-12 w-12 flex-none"/>
        <div class="flex flex-col w-3/4 ml-3 text-white">
          <h3 class="text-white text-base font-bold">Front Office</h3>
          <p class="text-xs">
            Manage front office settings and appointments
          </p>
        </div>
      </div>
      <div class="h-36 w-full bg-white px-4 flex items-center cursor-pointer">
        <UserGroupIcon class="text-black h-12 w-12 flex-none"/>
        <div class="flex flex-col w-3/4 ml-3 text-black">
          <h2 class="text-black text-base font-bold">Patients</h2>
          <p class="text-xs">
            Manage patients infomation and settings
          </p>
        </div>
      </div>
      <div class="h-36 w-full bg-white px-4 flex items-center cursor-pointer">
        <PhotographIcon class="text-black h-12 w-12 flex-none"/>
        <div class="flex flex-col w-3/4 ml-3 text-black">
          <h2 class="text-black text-base font-bold">Imaging</h2>
          <p class="text-xs">
            Settings and management for imaging
          </p>
        </div>
      </div>
      <div class="h-36 w-full bg-white px-4 flex items-center cursor-pointer" @click="showConfig('custom')">
        <AdjustmentsIcon class="text-black h-12 w-12 flex-none"/>
        <div class="flex flex-col w-3/4 ml-3 text-black">
          <h2 class="text-black text-base font-bold">Custom Settings</h2>
          <p class="text-xs">
            Manage time slots, departments, and others
          </p>
        </div>
      </div>
      <div class="h-36 w-full bg-white px-4 flex items-center cursor-pointer" @click="showConfig('billing')">
        <CashIcon class="text-black h-12 w-12 flex-none"/>
        <div class="flex flex-col w-3/4 ml-3 text-black">
          <h2 class="text-black text-base font-bold">Billing</h2>
          <p class="text-xs">
            Manage billing controls, currency, amounts, treatments
          </p>
        </div>
      </div>
      <div class="h-36 w-full bg-white px-4 flex items-center cursor-pointer">
        <LibraryIcon class="text-black h-12 w-12 flex-none"/>
        <div class="flex flex-col w-3/4 ml-3 text-black">
          <h2 class="text-black text-base font-bold">Insurance</h2>
          <p class="text-xs">
            Manage insurance claims and payments
          </p>
        </div>
      </div>
      <div class="h-36 w-full bg-white px-4 flex items-center cursor-pointer" @click="showConfig('users')">
        <UserIcon class="text-black h-12 w-12 flex-none"/>
        <div class="flex flex-col w-3/4 ml-3 text-black">
          <h2 class="text-black text-base font-bold">Users</h2>
          <p class="text-xs">
            Create new users, manage uses, edit and delete
          </p>
        </div>
      </div>
      </div>
   </div>
            <div class="flex w-2/3 p-10">
                <div class="w-full overflow-auto">
                    <Billing v-if='billing'/>
                    <CustomsConfig v-if='custom'/>
                    <Users v-if='users'/>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import {
  UserGroupIcon,
  PhotographIcon,
  AdjustmentsIcon,
  CashIcon,
  LibraryIcon,
  UserIcon,
  DesktopComputerIcon,
} from '@heroicons/vue/outline';
import { ref } from 'vue';
import SideBar from '@/components/shared/SideBar.vue';
import NavBar from '@/components/shared/NavBar.vue';
import Billing from '@/components/configurations/settings/ui/billing.vue';
import CustomsConfig from '@/components/configurations/settings/ui/customConfig.vue';
import Users from '@/components/configurations/settings/ui/allUsers.vue';

export default {
  components: {
    SideBar,
    NavBar,
    UserGroupIcon,
    PhotographIcon,
    AdjustmentsIcon,
    CashIcon,
    LibraryIcon,
    UserIcon,
    DesktopComputerIcon,
    CustomsConfig,
    Users,
    Billing,
  },
  setup() {
    const custom = ref(false);
    const users = ref(false);
    const billing = ref(false);

    const showConfig = (config) => {
      if (config === 'custom') {
        custom.value = true;
        users.value = false;
        billing.value = false;
      }
      if (config === 'users') {
        custom.value = false;
        users.value = true;
        billing.value = false;
      }
      if (config === 'billing') {
        custom.value = false;
        users.value = false;
        billing.value = true;
      }
    };
    return {
      custom,
      users,
      billing,
      showConfig,
    };
  },
};
</script>

因为我希望当用户单击该div时,它会更改背景和文本颜色,并在右侧呈现一个组件。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-01 10:19:00

您可以简单地将类属性绑定到容器中,这样它就获得了所需的值。

代码语言:javascript
复制
<div :class="desiredClass"  class="h-36 w-full.....

showConfig函数中,可以相应地更新desiredClass的值。

代码语言:javascript
复制
this.desiredClass = "h-26"

您还可能希望将desiredClass声明为反应性状态。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71688799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档