admin管理员组

文章数量:1296921

Currently using VueJs and Bootstrap Vue and I'm wondering how to use appending the "active" tag to the Nav links I have set up.

   <div>
        <b-nav tabs align="center">

            <b-nav-item>
                <b-link to="/">Home</b-link>
            </b-nav-item>

             <b-nav-item>
                <b-link to="/table">Table</b-link>
            </b-nav-item>

        </b-nav>
    </div>

How would I be able to turn it into the following?

    <div>
        <b-nav tabs align="center">

            <b-nav-item>
                <b-link to="/" active>Home</b-link>
            </b-nav-item>

             <b-nav-item>
                <b-link to="/table">Table</b-link>
            </b-nav-item>

        </b-nav>
    </div>

I've tried @click events to toggle a boolean and set a class that way but I've not had much success.

Currently using VueJs and Bootstrap Vue and I'm wondering how to use appending the "active" tag to the Nav links I have set up.

   <div>
        <b-nav tabs align="center">

            <b-nav-item>
                <b-link to="/">Home</b-link>
            </b-nav-item>

             <b-nav-item>
                <b-link to="/table">Table</b-link>
            </b-nav-item>

        </b-nav>
    </div>

How would I be able to turn it into the following?

    <div>
        <b-nav tabs align="center">

            <b-nav-item>
                <b-link to="/" active>Home</b-link>
            </b-nav-item>

             <b-nav-item>
                <b-link to="/table">Table</b-link>
            </b-nav-item>

        </b-nav>
    </div>

I've tried @click events to toggle a boolean and set a class that way but I've not had much success.

Share asked Jun 7, 2019 at 9:26 Mtlj1991Mtlj1991 1972 gold badges5 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

You can use the $route object to check the route name and bind it to the active prop.

<b-link to="/table" :active='$route.name =="Table"'>Table</b-link>

本文标签: javascriptToggling active nav items with BootstrapVue and VueJsStack Overflow