How Vue routerlink and v-for change prop
P粉717595985
P粉717595985 2023-09-09 18:41:15
0
1
312

I'm using this code:

   <router-link
                    v-for="item in navigation"
                    :key="item.name"
                    :to="item.to"
                    @click="(item.current = true) "
                    :class="[
                      item.current
                        ? 'bg-gray-900 text-white'
                        : 'text-gray-300 hover:bg-gray-700 hover:text-white',
                      'group flex items-center px-2 py-2 text-base font-medium rounded-md',
                    ]"
                  >

 const navigation = [
    { name: "Dashboard", to: "/", icon: HomeIcon, current: false },
    { name: "About", to: "/about", icon: UsersIcon, current: false },
    { name: "Projects", to: "about", icon: FolderIcon, current: false },
  ];`

My question is how to use routerlink to achieve this function? I want it to change to true when you select the current item. so that the tailwind level changes. I tried (item.current = true) but this changes all current objects to true. The code you see is from the Tailwind component sidebar example. https://tailwindui.com/components/application-ui/application-shells/sidebar

I use active-class now and it works somehow. But I still want to know what to do.

P粉717595985
P粉717595985

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!