美文网首页
vue 页面缓存代替keepalive

vue 页面缓存代替keepalive

作者: 臭臭的胡子先生 | 来源:发表于2024-03-20 14:51 被阅读0次

    下载

    npm i vue-navigation --save
    

    main.js

    import Navigation from 'vue-navigation';
    Vue.use(Navigation, {router}); // vue-router 实例
    

    app.vue

    <template>
      <div id="app">
        <navigation>
          <router-view></router-view>
        </navigation>
       
      </div>
    </template>
    

    页面跳转时报如下错误 在main.js 加入下方代码


    image.png
    import Router from 'vue-router'
    const originalPush = Router.prototype.push
    Router.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
    return originalPush.call(this, location).catch(err => err)
    }
    
    

    router 中必须要有name 才会生效

    export default new Router({
      routes: [
        {
          path: "/index",
          name: "index",
          component:  () => import("@/views/home/index")
        },
    

    相关文章

      网友评论

          本文标题:vue 页面缓存代替keepalive

          本文链接:https://www.haomeiwen.com/subject/dluxtjtx.html