mirror of
https://github.com/youzan/vant.git
synced 2025-12-24 02:02:09 +08:00
[Doc] optimize document site (#1013)
This commit is contained in:
@@ -3,31 +3,28 @@
|
||||
*/
|
||||
|
||||
import Vue from 'vue';
|
||||
import i18n from 'packages/mixins/i18n';
|
||||
import { Locale, Toast, Dialog } from 'packages';
|
||||
import { DemoBlock, DemoSection } from 'vant-doc';
|
||||
import { camelize } from 'packages/utils';
|
||||
import progress from 'nprogress';
|
||||
import i18n from '../../packages/mixins/i18n';
|
||||
import Vant, { Lazyload } from '../../packages';
|
||||
import VantDoc, { DemoBlock, DemoSection } from 'vant-doc';
|
||||
import VueRouter from 'vue-router';
|
||||
import { Locale, Toast, Dialog } from '../../packages';
|
||||
import { camelize } from '../../packages/utils';
|
||||
|
||||
const demoBaseMixin = {
|
||||
beforeCreate() {
|
||||
const { name, i18n } = this.$options;
|
||||
if (name && i18n) {
|
||||
const formattedI18n = {};
|
||||
const camelizedName = camelize(name);
|
||||
Object.keys(i18n).forEach(key => {
|
||||
formattedI18n[key] = { [camelizedName]: i18n[key] };
|
||||
});
|
||||
Locale.add(formattedI18n);
|
||||
}
|
||||
}
|
||||
};
|
||||
Vue
|
||||
.use(Vant)
|
||||
.use(VantDoc)
|
||||
.use(VueRouter)
|
||||
.use(Lazyload, {
|
||||
lazyComponent: true
|
||||
});
|
||||
|
||||
Vue.component('demo-block', DemoBlock);
|
||||
Vue.component('demo-section', DemoSection);
|
||||
|
||||
window.Toast = Toast;
|
||||
window.Dialog = Dialog;
|
||||
Vue.mixin(i18n);
|
||||
Vue.mixin(demoBaseMixin);
|
||||
Vue.component('demo-block', DemoBlock);
|
||||
Vue.component('demo-section', DemoSection);
|
||||
|
||||
Locale.add({
|
||||
'zh-CN': {
|
||||
@@ -85,3 +82,30 @@ Locale.add({
|
||||
passwordPlaceholder: 'Password'
|
||||
}
|
||||
});
|
||||
|
||||
export function asyncWrapper(component) {
|
||||
return function(r) {
|
||||
progress.start();
|
||||
component(r).then(() => {
|
||||
progress.done();
|
||||
}).catch(() => {
|
||||
progress.done();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function componentWrapper(component, name) {
|
||||
component = component.default;
|
||||
name = 'demo-' + name;
|
||||
component.name = name;
|
||||
const { i18n } = component;
|
||||
if (i18n) {
|
||||
const formattedI18n = {};
|
||||
const camelizedName = camelize(name);
|
||||
Object.keys(i18n).forEach(key => {
|
||||
formattedI18n[key] = { [camelizedName]: i18n[key] };
|
||||
});
|
||||
Locale.add(formattedI18n);
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
@@ -1,24 +1,5 @@
|
||||
// This file is auto gererated by build/bin/build-entry.js
|
||||
import './common';
|
||||
|
||||
import progress from 'nprogress';
|
||||
|
||||
function asyncWrapper(component) {
|
||||
return function(r) {
|
||||
progress.start();
|
||||
component(r).then(() => {
|
||||
progress.done();
|
||||
}).catch(() => {
|
||||
progress.done();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function componentWrapper(component, name) {
|
||||
component = component.default;
|
||||
component.name = 'demo-' + name;
|
||||
return component;
|
||||
}
|
||||
import { asyncWrapper, componentWrapper } from './common';
|
||||
|
||||
export default {
|
||||
'actionsheet': asyncWrapper(r => require.ensure([], () => r(componentWrapper(require('./views/actionsheet'), 'actionsheet')), 'actionsheet')),
|
||||
|
||||
@@ -2,21 +2,11 @@ import Vue from 'vue';
|
||||
import VueRouter from 'vue-router';
|
||||
import App from './WapApp';
|
||||
import routes from './router';
|
||||
import Vant, { Lazyload } from 'packages';
|
||||
import VantDoc from 'vant-doc';
|
||||
import 'packages/vant-css/src/index.css';
|
||||
import 'packages/vant-css/src/icon-local.css';
|
||||
import '../../packages/vant-css/src/index.css';
|
||||
import '../../packages/vant-css/src/icon-local.css';
|
||||
import 'vant-doc/src/helper/touch-simulator';
|
||||
import './components/nprogress.css';
|
||||
|
||||
Vue
|
||||
.use(Vant)
|
||||
.use(VantDoc)
|
||||
.use(VueRouter)
|
||||
.use(Lazyload, {
|
||||
lazyComponent: true
|
||||
});
|
||||
|
||||
const router = new VueRouter({
|
||||
mode: 'hash',
|
||||
base: '/zanui/vant/examples',
|
||||
|
||||
Reference in New Issue
Block a user