How to make Vue Router add 'link-exact-active-class' at the end of class list?
P粉193307465
P粉193307465 2024-02-25 17:49:38
0
1
350

I tried using thelinkExactActiveClassparameter in the router constructor to highlight active links in the navigation bar.

My problem is that the active class is added to the beginning of the css class list, which means other classes override it.

This is my router configuration:

const router = createRouter({ history: createWebHistory(process.env.BASE_URL), routes, linkExactActiveClass: 'text-yellow-500', });

router-linkThe elements look like this:

  • Manage
  • question:

    text-yellow-500classes are indeed added before existing css classes. This causes the yellow text to be overwritten by thetext-whiteclass. How can I change this?

    P粉193307465
    P粉193307465

    reply all (1)
    P粉517475670

    A simple solution is to use tailwind(documentation) in the class

    Try using it like this:

    const router = createRouter({ history: createWebHistory(process.env.BASE_URL), routes, linkExactActiveClass: '!text-yellow-500', });

    Normally, I don't like this approach, but I don't think there is any other easy option

    PS: Make sure you are using at least tailwind 2.1 andJITmode

      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!