Vue2:路由组件缓存技术-二、案例

时间:2024-03-03 16:46:34

home组件中,有两个路由组件可以切换

    <div>
        <h2>Home组件内容</h2>
        <div>
            <ul class="nav nav-tabs">
                <li>
                    <router-link class="list-group-item" active-class="active" to="/home/news">News</router-link>
                </li>
                <li>
                    <router-link class="list-group-item" active-class="active" to="/home/message">Message</router-link>
                </li>
            </ul>
                <router-view></router-view>
        </div>
    </div>

缓存一个路由组件

            <keep-alive include="News">
                <router-view></router-view>
            </keep-alive>

缓存多个路由组件

             <keep-alive :include="['News','Message']">