feat(cli): support switch site version

This commit is contained in:
陈嘉涵
2019-12-11 11:50:07 +08:00
parent a78fc55079
commit 0a45afad42
4 changed files with 25 additions and 4 deletions

View File

@@ -3,6 +3,7 @@
<van-doc
:lang="lang"
:config="config"
:versions="versions"
:simulator="simulator"
:lang-configs="langConfigs"
>
@@ -13,7 +14,7 @@
<script>
import VanDoc from './components';
import { config } from 'site-desktop-shared';
import { config, packageVersion } from 'site-desktop-shared';
import { setLang } from '../common/locales';
function getPublicPath() {
@@ -33,6 +34,7 @@ export default {
data() {
return {
packageVersion,
simulator: `${getPublicPath()}mobile.html${location.hash}`
};
},
@@ -59,6 +61,14 @@ export default {
}
return config.site;
},
versions() {
if (config.site.versions) {
return [{ label: packageVersion }, ...config.site.versions];
}
return null;
}
},

View File

@@ -18,14 +18,16 @@
<li ref="version" v-if="versions" class="van-doc-header__top-nav-item">
<span class="van-doc-header__cube van-doc-header__version" @click="toggleVersionPop">
{{ versions[0] }}
{{ versions[0].label }}
<transition name="van-doc-dropdown">
<div v-if="showVersionPop" class="van-doc-header__version-pop">
<div
v-for="item in versions"
class="van-doc-header__version-pop-item"
@click="onSwitchVersion(item)"
>{{ item }}</div>
>
{{ item.label }}
</div>
</div>
</transition>
</span>
@@ -107,7 +109,7 @@ export default {
},
onSwitchVersion(version) {
this.$emit('switch-version', version);
location.href = version.link;
}
}
};