<template>
<div id="app">
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link>
</div>
<router-view :key="key"></router-view>
<div @click="jump('Edison')"><h1>Edison</h1></div>
<div @click="jump('Ero')"><h1>Ero</h1></div>
</div>
</template>
<script>
export default {
methods: {
jump(dest) {
this.$router.replace({ path: `/test/${dest}` }, route => {
console.log(route)
}, err => {
console.log(err)
})
}
},
computed: {
key() {
// 只要保证 key 唯一性就可以了,保证不同页面的 key 不相同
return this.$route.fullPath
}
}
}
</script>
<style lang="scss">
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
#nav {
padding: 30px;
a {
font-weight: bold;
color: #2c3e50;
&.router-link-exact-active {
color: #42b983;
}
}
}
</style>
网友评论