<template>
<p>
a.vue
<router-link to="/a/a1">a1</router-link>
<router-link to="/a/a2">a2</router-link>
<br>
<button @click="gta1()">a1</button>
<router-view></router-view>
</p>
</template>
<script>
export default{
methods:{
gta1(){
router.push({path:'a'}) //这里报错了, “router is not defined”
}
}
}
</script>
I would like to ask, how can I obtain the router and implement programmatic navigation?
this.$router
See component injection for details
$router: router instance.
$route: currently activated routing information object.