路由做代码跳转
拿到router对象this.$router
<template>
<div id="app">
<!-- <router-link to="/home">首页</router-link>-->
<!-- <router-link to="/about">关于</router-link>-->
<button @click="home">首页</button>
<button @click="about">关于</button>
<router-view></router-view>
</div>
</template>
<script>
export default {
name: 'App',
methods :{
home:function (){
this.$router.push('/home')
},
about:function (){
this.$router.push('/about')
}
}
}
</script>
<style>
</style>
附:使用replace()也可
this.$router.replace('/about')