feat(cli): improve nav route

This commit is contained in:
陈嘉涵 2019-12-12 20:47:07 +08:00
parent 1aaa8b3945
commit d511508e3b
5 changed files with 30 additions and 12 deletions

View File

@ -60,7 +60,7 @@
"vue": ">= 2.5.22" "vue": ">= 2.5.22"
}, },
"devDependencies": { "devDependencies": {
"@vant/cli": "^2.0.0-beta.18", "@vant/cli": "^2.0.0-beta.19",
"vue": "^2.6.10", "vue": "^2.6.10",
"vue-template-compiler": "^2.6.10" "vue-template-compiler": "^2.6.10"
}, },

View File

@ -32,11 +32,8 @@ export default {
}, },
props: { props: {
navConfig: Array, lang: String,
base: { navConfig: Array
type: String,
default: ''
}
}, },
data() { data() {
@ -52,6 +49,10 @@ export default {
top: this.top + 'px', top: this.top + 'px',
bottom: this.bottom + 'px' bottom: this.bottom + 'px'
}; };
},
base() {
return this.lang ? `/${this.lang}` : '';
} }
}, },

View File

@ -1,5 +1,5 @@
<template> <template>
<router-link v-if="item.path" active-class="active" :to="base + item.path" v-html="itemName" /> <router-link v-if="item.path" :class="{ active }" :to="path" v-html="itemName" />
<a v-else-if="item.link" :href="item.link" v-html="itemName" /> <a v-else-if="item.link" :href="item.link" v-html="itemName" />
<a v-else v-html="itemName " /> <a v-else v-html="itemName " />
</template> </template>
@ -17,6 +17,23 @@ export default {
itemName() { itemName() {
const name = (this.item.title || this.item.name).split(' '); const name = (this.item.title || this.item.name).split(' ');
return `${name[0]} <span>${name.slice(1).join(' ')}</span>`; return `${name[0]} <span>${name.slice(1).join(' ')}</span>`;
},
path() {
const { path } = this.item;
return this.base ? `${this.base}/${path}` : path;
},
active() {
if (this.$route.path === this.path) {
return true;
}
if (this.item.path === 'home') {
return this.$route.path === this.base;
}
return false;
} }
} }
}; };

View File

@ -7,7 +7,7 @@
:lang-configs="langConfigs" :lang-configs="langConfigs"
@switch-version="$emit('switch-version', $event)" @switch-version="$emit('switch-version', $event)"
/> />
<doc-nav :base="base" :nav-config="config.nav" /> <doc-nav :lang="lang" :nav-config="config.nav" />
<doc-container :has-simulator="!!simulator "> <doc-container :has-simulator="!!simulator ">
<doc-content> <doc-content>
<slot /> <slot />

View File

@ -1452,10 +1452,10 @@
lodash.unescape "4.0.1" lodash.unescape "4.0.1"
semver "^6.3.0" semver "^6.3.0"
"@vant/cli@^2.0.0-beta.18": "@vant/cli@^2.0.0-beta.19":
version "2.0.0-beta.18" version "2.0.0-beta.19"
resolved "https://registry.npm.taobao.org/@vant/cli/download/@vant/cli-2.0.0-beta.18.tgz#073cf13b44fcf772c510e0a142a627cb3049aa5b" resolved "https://registry.npm.taobao.org/@vant/cli/download/@vant/cli-2.0.0-beta.19.tgz#2e9ac47b3765221629f3adaf42a4ecb2e7e0ef1a"
integrity sha1-BzzxO0T893LFEOChQqYnyzBJqls= integrity sha1-LprEezdlIhYp862vQqTssufg7xo=
dependencies: dependencies:
"@babel/core" "^7.7.4" "@babel/core" "^7.7.4"
"@babel/plugin-proposal-optional-chaining" "^7.7.4" "@babel/plugin-proposal-optional-chaining" "^7.7.4"