在js中調用vue router的路由方法和react有所差異,react中不能直接調(之前項目遇到的情況),而vue中通過引入路由,然后直接調用即可。
具體步驟
1 將定義好的路由導出
const router = new VueRouter({
mode: "history",
base: process.env.BASE_URL,
routes
})
export default router
2 在需要使用路由方法的頁面中引入路由,然后直接調用使用
import router from '../router'
export function logout() {
window.sessionStorage.clear()
window.localStorage.clear()
router.replace({ path: "/login" })
}