想使用vue的router来跳转页面,但是报错识别不了push,在上面可以正常使用.$message弹出消息提示框
需要挂载在Vue实例中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
<button @click="toAbout">toAbout</button>
<router-view></router-view>
</div>
<script src="https://cdn.staticfile.org/vue/2.6.9/vue.min.js"></script>
<script src="https://cdn.staticfile.org/vue-router/3.4.3/vue-router.min.js"></script>
<script>
const com = {
template: `
<div>
<h1>about</h1>
</div>
`
}
const routes = [
{ path: '/about', component: com }
]
const router = new VueRouter({
routes
})
const App = new Vue({
el: '#app',
router,
methods: {
toAbout() {
this.$router.push('/about')
}
}
})
</script>
</body>
</html>
向vue上 挂载router 你没挂载肯定this用不了