美文网首页
vue-router

vue-router

作者: 苍老师的眼泪 | 来源:发表于2022-01-03 11:30 被阅读0次
    <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>
    
    

    相关文章

      网友评论

          本文标题:vue-router

          本文链接:https://www.haomeiwen.com/subject/xljxcrtx.html