refactor(recorder): Render components dynamically based on hash
This commit is contained in:
parent
c181e3ae34
commit
5ac87cfe37
2 changed files with 41 additions and 7 deletions
|
|
@ -1,7 +1,9 @@
|
|||
<template>
|
||||
<div>
|
||||
{{ path }} {{ count }}
|
||||
</div>
|
||||
<a :href="'#Path/' + path ">
|
||||
<div>
|
||||
{{ path }} {{ count }}
|
||||
</div>
|
||||
</a>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
|
|
|||
|
|
@ -1,15 +1,47 @@
|
|||
<template>
|
||||
<div>
|
||||
<recorder-detail/>
|
||||
<component :is="current_component"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import RecorderDetail from "./RecorderDetail.vue"
|
||||
import PathDetail from "./PathDetail.vue"
|
||||
|
||||
export default {
|
||||
name: "RecorderRoot",
|
||||
components: {
|
||||
RecorderDetail,
|
||||
}
|
||||
data () {
|
||||
return {
|
||||
current_component: RecorderDetail
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.set_component()
|
||||
window.onhashchange = this.set_component
|
||||
},
|
||||
methods: {
|
||||
set_component: function () {
|
||||
var routes = {
|
||||
"#": RecorderDetail,
|
||||
"#Path": PathDetail,
|
||||
}
|
||||
var route = this.get_route()
|
||||
this.current_component = routes[route.route]
|
||||
},
|
||||
get_route: function () {
|
||||
var hash = window.location.hash
|
||||
if (hash) {
|
||||
var array = hash.split("/")
|
||||
var route = array[0]
|
||||
var param = array.slice(1).join("/")
|
||||
}
|
||||
else {
|
||||
var route = "#"
|
||||
var param = ""
|
||||
}
|
||||
return { route, param }
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue