【发布时间】:2017-08-19 04:44:42
【问题描述】:
我在使用 vue-router 时遇到了一些问题。我的路线是这样设置的:
const routes = [
{ path: '/', component: a },
{ path: '/a', component: a },
{ path: '/b', component: b },
{ path: '/c', component: c }
]
如您所见,我想在页面加载时加载组件a。但我不希望在页面加载时 URL 更改为 /a。但是我想在与a 组件相关的<router-link> 上触发router-link-active-class,即使我仍在/。
我尝试过一些简单的 JS,例如:
if(window.location.hash === '#/') {
var el = document.querySelector('#drawerList').firstElementChild;
el.className += 'router-link-active';
}
但是,当我单击 /b 或 /c 的链接时,vue 并没有再次删除该类。你们中的任何人都可以提示我正确的方向吗?
【问题讨论】:
标签: javascript vue.js vue-router