|
|
@ -10,28 +10,35 @@ export default { |
|
|
|
name: 'App', |
|
|
|
|
|
|
|
watch: { |
|
|
|
$route(to){ |
|
|
|
const path = `/${to.path.split('/')[1]}` |
|
|
|
this.setCode(path) |
|
|
|
$route(to, from) { |
|
|
|
if(to.name){ |
|
|
|
const arr = to.path.split('/') |
|
|
|
const path = `/${arr[arr.length-1]}` |
|
|
|
this.setCode(path) |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
methods: { |
|
|
|
setCode(path) { |
|
|
|
console.log('path: ', path); |
|
|
|
router.options.routes.forEach(first => { |
|
|
|
if(first && first.path && first.path === path){ |
|
|
|
console.log('first.code: ',first, first.code); |
|
|
|
localStorage.setItem('code', first.code) |
|
|
|
return; |
|
|
|
}else{ |
|
|
|
if(first.children && first.children.length){ |
|
|
|
first.children.forEach(second => { |
|
|
|
if(second && second.path && second.path === path){ |
|
|
|
console.log('second.code: ', second.code); |
|
|
|
localStorage.setItem('code', second.code) |
|
|
|
return; |
|
|
|
}else{ |
|
|
|
if(second.children && second.children.length){ |
|
|
|
second.children.forEach(third => { |
|
|
|
if(third && third.path && third.path === path){ |
|
|
|
console.log('third.code: ', third.code); |
|
|
|
localStorage.setItem('code', third.code) |
|
|
|
return; |
|
|
|
} |
|
|
|