Vue 페이지 수동 새로 고침, 탐색 표시줄 활성화 항목을 초기 상태로 복원
원리: 매번 리셋할 때마다 Vue를 다시 실례화합니다. 즉created 방법을 호출합니다.
<template>
<el-menu :default-active="defaultActiveIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect" :router="true">
<el-menu-item index="/"> </el-menu-item>
<el-menu-item index="/enterpriseManager"> </el-menu-item>
<el-menu-item index="/orderManager"> </el-menu-item>
<el-menu-item index="/systemManager"> </el-menu-item>
</el-menu>
</template>
<script>
export default {
name: 'app',
data () {
return {
defaultActiveIndex: "/"
}
},
created() {
// ,
// data observed
this.fetchData()
},
methods: {
handleSelect(index){
this.defaultActiveIndex = index;
},
jumpTo(url){
this.defaultActiveIndex = url;
this.$router.push(url); // go
},
fetchData () {
var cur_path = this.$route.path; //
var routers = this.$router.options.routes; //
var nav_type = "";
for(var i=0; i<routers.length; i++){
var children = routers[i].children;
if(children){
for(var j=0; j<children.length; j++){
var grand_children = children[j].children;
if(grand_children){
for(var k=0; k<grand_children.length; k++){
if(grand_children[k].path == cur_path){
nav_type = routers[i].type;
break;
}
}
}
}
}
}
if(nav_type == "home"){
this.defaultActiveIndex = "/";
} else if(nav_type == "enterprise"){
this.defaultActiveIndex = "/enterpriseManager";
}
}
}
watch: {
'$route': 'fetchData'
}
}
</script>
라우터 구성 형식 첨부:
export default [
{
path: '/',
type: 'home', // type
name: 'home',
redirect: '/dashboard',
component: Home,
menuShow: true,
children: [
{
path: '/dashboard',
component: HomeNav,
name: 'dashboard',
leaf: true, //
iconCls: 'icon-home', // class
menuShow: true,
children: [
{ path: '/dashboard', component: Dashboard, name: ' ', menuShow: true }
]
},
{
path: '/mySet',
component: HomeNav,
name: ' ',
iconCls: 'el-icon-menu',
menuShow: true,
children: [
{ path: '/mySet/plan', component: Plan, name: ' ', menuShow: true },
{ path: '/mySet/maillist', component: Maillist, name: ' ', menuShow: true }
]
}
]
},
{
path: '/enterpriseManager',
type: 'enterprise',
name: 'enterprise',
component: Home,
redirect: '/enterprise/list',
menuShow: true,
children: [
{
path: '/enterpriseList',
component: EnterpriseNav,
name: 'enterpriseList',
leaf: true, //
iconCls: 'icon-home', // class
menuShow: true,
children: [
{ path: '/enterprise/list', component: EnterpriseList, name: ' ', menuShow: true }
]
},
{
path: '/enterpriseAdd',
component: EnterpriseNav,
name: 'enterpriseAdd',
leaf: true, //
iconCls: 'el-icon-menu',
menuShow: true,
children: [
{ path: '/enterprise/add', component: EnterpriseAdd, name: ' ', menuShow: true }
]
},
{
path: '/enterpriseValidate',
component: EnterpriseNav,
name: 'enterpriseValidate',
leaf: true, //
iconCls: 'el-icon-menu',
menuShow: true,
children: [
{ path: '/enterprise/validate', component: EnterpriseValidate, name: ' ', menuShow: true }
]
}
]
}
]
보충 지식: vue 수동 새로 고침 보기 및 기타 작은 문제최근에 수중에 있는angularJS+jquery의 각종 7, 8, 8 구성 요소를 사용하여 쓴 페이지를 vue+elementUI로 다시 썼는데 정말 매끄러워서 vue와 elementUI의 사소한 문제를 기록한다
1. 만약에 vue의 데이터 구조가 비교적 방대하다면 모델 업데이트가 나타날 가능성이 높고 보기가 업데이트되지 않고/모델과 보기가 업데이트되지 않고 틀리지 않을 수 있습니다. 이때 vue의 데이터를 수동으로 업데이트해야 합니다.change나 click 이벤트에서this.$를 사용합니다.forceUpdate() 수동으로 뷰 새로 고침
//
changeSef: function () {
//
var that = this;
that.$forceUpdate();
},
2. vue에서 setTimeout 사용하기
//
setTimeout(bidOrderInit, 200);
// , , setTimeout this window ,
// vue this
//
// ie
setTimeout(()=> {
this.bidOrderInit();
}, 200);
// ie
setTimeout(function () {
this.bidOrderInit();
}, 200);
위의 이 Vue 페이지를 수동으로 리셋하여 네비게이션 표시줄 활성화 항목을 초기 상태로 복원하는 것이 바로 편집자가 여러분에게 공유한 모든 내용입니다. 여러분께 참고가 되고 저희를 많이 사랑해 주시기 바랍니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Vue Render 함수로 DOM 노드 코드 인스턴스 만들기render에서createElement 함수를 사용하여 DOM 노드를 만드는 것은 직관적이지 않지만 일부 독립 구성 요소의 디자인에서 특수한 수요를 충족시킬 수 있습니다.간단한 렌더링 예는 다음과 같습니다. 또한 v...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.