比如,我的Head組件是共用的APP.js<template>
<heads></heads> <router-view transition="fade" transition-mode="out-in"></router-view></template>其中Heads.js中title是需要根據(jù)路由來變化的,相當于html中的<title>標簽<template>
<x-header :left-options="{backText:'',showBack:true}">{{title}}</x-header></template>我的思路是這樣的:用計算屬性根據(jù)路由路徑來匹配,然后返回。computed: {
title: function () {
switch (this.$route.path) { case '/':
return '首頁'
case '/a':
return '頁面a'
case '/b':
return '頁面b'
case '/c':
return '頁面c' }
}
}這樣做的話如果路由越來越多case也會越來越多,不好維護。麻煩大神能指點指點。
共用組件中某個數(shù)據(jù)隨著路由改變而改變?
炎炎設計
2018-09-14 10:09:25