vue 二级路由
效果
在二级路由利用路由守卫监听效果
组合api
代码如下
<template>
<nav>
<router-link to="/">首页</router-link> |
<router-link to="/about">关于我们</router-link>
</nav>
<router-view />
<div>{{data.num}}</div>
<button @click="fun">点赞</button>
</template>
<script setup>
import { reactive } from "vue";
const data = reactive({
num : 100
})
const fun = () =>{
data.num++;
}
</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>
效果