解决vue中路由刷新之后,当前页面的状态自动转换到首页的位置
<router-link
:class="{'active' : selectIndex == l.index}"
:to="l.to"
v-for="(l,i) of list"
:key="i"
:data-i="l.index"
>{{l.title}}</router-link>
data() {
return {
list: [
{ index: 0, title: "首页", to: "/" },
{ index: 1, title: "关于我们", to: "/about" },
{ index: 2, title: "极客深度", to: "" },
{ index: 3, title: "合作品牌", to: "/team" },
{ index: 4, title: "体验店合作", to: "" },
{ index: 5, title: "免费试用", to: "" }
],
selectIndex: 0,
hash: window.location.hash
};
},
created() {
if (this.hash == "#/team") {
this.selectIndex = 3;
}else if(this.hash == "#/about"){
this.selectIndex = 1;
}
},