小编Chr*_*ell的帖子

在历史模式下从子路由刷新时组件被挂载两次

我在历史模式下使用 vue-router。当我在子路由“/dashboard”上并刷新页面时,<ccp/>组件被安装了两次。在 ccp 组件中,我正在控制台登录创建和安装的钩子。我看到每个控制台输出两次。有什么想法吗?提前感谢您的关注!

编辑:在初始应用程序加载时,<ccp/>仅创建和安装一次。

这是代码:

应用程序.vue:

<template>
    <div v-show="isConnected">
      <ccp/>
      <router-view/>
    </div>
</template>

<script>
     // blah blah blah - doing stuff and then pushing route to /dashboard
    return this.$router.push({name: "dashboard"});
</script>
Run Code Online (Sandbox Code Playgroud)

路由器.js

export default new Router({
mode: "history",
routes: [
// DEFAULT ROUTE
{
  path: "/",
  name: "root",
  alias: store.getters.isDemoMode ? "/demo" : "/app" // isDemoMode is false for this test however I wanted to show the alias config in case that is part of …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-router

5
推荐指数
1
解决办法
4479
查看次数

标签 统计

javascript ×1

vue-router ×1

vue.js ×1