admin管理员组文章数量:1391964
I am using vue-router in history mode. When I am on on child route "/dashboard" and I refresh the page, the <ccp/>
ponent is mounted twice. In the ccp ponent I am console logging in the created and mounted hook. I see that console output twice for each one. Any thoughts? Thanks in advance for looking!
Edit: On initial app load, <ccp/>
is created and mounted only once.
Here's the code:
App.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>
router.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 the problem.
},
{
path: "/demo",
name: "demo",
ponent: Demo
},
{
path: "/app",
name: "app",
ponent: App,
children: [
{
path: "/dashboard",
name: "dashboard",
ponent: Dashboard
}
]
}
})
I am using vue-router in history mode. When I am on on child route "/dashboard" and I refresh the page, the <ccp/>
ponent is mounted twice. In the ccp ponent I am console logging in the created and mounted hook. I see that console output twice for each one. Any thoughts? Thanks in advance for looking!
Edit: On initial app load, <ccp/>
is created and mounted only once.
Here's the code:
App.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>
router.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 the problem.
},
{
path: "/demo",
name: "demo",
ponent: Demo
},
{
path: "/app",
name: "app",
ponent: App,
children: [
{
path: "/dashboard",
name: "dashboard",
ponent: Dashboard
}
]
}
})
Share
Improve this question
edited Sep 16, 2018 at 5:26
Chris Newell
asked Sep 16, 2018 at 3:57
Chris NewellChris Newell
1472 silver badges10 bronze badges
4
- 1 I think issue is somewhere in your page / javascript .. You are possibly importing this into another file which makes it run 2x .. I had similar issue where I had 1 on click listener but I imported the main app.js into another file and it was executing 2x – I am Cavic Commented Sep 16, 2018 at 4:00
- 1 I think if that was the case it would mount twice on initial app load right? – Chris Newell Commented Sep 16, 2018 at 4:02
- Just go through your JS files and see if you are doing import anywhere .. If not make sure in your html you are not adding it 2x by mistake – I am Cavic Commented Sep 16, 2018 at 4:04
- Dang, I was hoping it was something as simple as that but I just went through all involved ponents, <ccp/> is only referenced once in App.vue and not anywhere else. Searched using vscode in the project root to confirm it's not imported anywhere else either. – Chris Newell Commented Sep 16, 2018 at 4:14
1 Answer
Reset to default 4It's mounted twice likely due to the App ponent also being part of your route. Your route named "app"
is mounting App again.
本文标签: javascriptComponent is mounted twice when refreshing from child route in history modeStack Overflow
版权声明:本文标题:javascript - Component is mounted twice when refreshing from child route in history mode - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744699375a2620473.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论