jiangwei小站
117 字
1 分钟
vue 路由返回不刷新
2022-07-01

router 路由配置 router/index.js

const routes = [
  {
    path: "/pageA",
    name: "pageA",
    component: () => import("../views/pageA.vue"),
    meta: {
      title: "我是页面A",
      keepAlive: true,
    },
  },
  {
    path: "/pageB",
    name: "pageB",
    component: () => import("../views/pageB.vue"),
    meta: {
      title: "我的页面B",
      keepAlive: false,
    },
  },
];
const router = new VueRouter({
  routes,
});

Vue.use(VueRouter);
<keep-alive>
	<router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
 <router-view v-if="!$route.meta.keepAlive"></router-view>
router.back();

chatgpt#

可以在路由配置中添加{reload: true},即可实现前进刷新,后退不刷新的效果。

const router = new VueRouter({
  routes: [
    {
      path: "/",
      name: "Home",
      component: Home,
      meta: {
        reload: true,
      },
    },
  ],
});