mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore(cli): vue global api change
This commit is contained in:
parent
9b3b1e896c
commit
e44d3955fc
@ -1,19 +1,18 @@
|
|||||||
import Vue from 'vue';
|
import { createApp } from 'vue';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
|
import VueRouter from 'vue-router';
|
||||||
import { router } from './router';
|
import { router } from './router';
|
||||||
import { scrollToAnchor } from './utils';
|
import { scrollToAnchor } from './utils';
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
const app = createApp({
|
||||||
Vue.config.productionTip = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
new Vue({
|
|
||||||
el: '#app',
|
el: '#app',
|
||||||
mounted() {
|
mounted() {
|
||||||
if (this.$route.hash) {
|
if (this.$route.hash) {
|
||||||
scrollToAnchor(this.$route.hash);
|
scrollToAnchor(this.$route.hash);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: h => h(App),
|
render: (h) => h(App),
|
||||||
router,
|
router,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(VueRouter);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import Vue from 'vue';
|
import { nextTick } from 'vue';
|
||||||
import VueRouter from 'vue-router';
|
import VueRouter from 'vue-router';
|
||||||
import { isMobile, decamelize } from '../common';
|
import { isMobile, decamelize } from '../common';
|
||||||
import { config, documents } from 'site-desktop-shared';
|
import { config, documents } from 'site-desktop-shared';
|
||||||
@ -48,7 +48,7 @@ function getRoutes() {
|
|||||||
if (locales) {
|
if (locales) {
|
||||||
routes.push({
|
routes.push({
|
||||||
path: '*',
|
path: '*',
|
||||||
redirect: route => `/${getLangFromRoute(route)}/`,
|
redirect: (route) => `/${getLangFromRoute(route)}/`,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
routes.push({
|
routes.push({
|
||||||
@ -66,7 +66,7 @@ function getRoutes() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
names.forEach(name => {
|
names.forEach((name) => {
|
||||||
const { component, lang } = parseName(name);
|
const { component, lang } = parseName(name);
|
||||||
|
|
||||||
if (component === 'home') {
|
if (component === 'home') {
|
||||||
@ -98,8 +98,6 @@ function getRoutes() {
|
|||||||
return routes;
|
return routes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vue.use(VueRouter);
|
|
||||||
|
|
||||||
export const router = new VueRouter({
|
export const router = new VueRouter({
|
||||||
mode: 'hash',
|
mode: 'hash',
|
||||||
routes: getRoutes(),
|
routes: getRoutes(),
|
||||||
@ -113,7 +111,7 @@ export const router = new VueRouter({
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.afterEach(() => {
|
router.afterEach(() => {
|
||||||
Vue.nextTick(() => window.syncPath());
|
nextTick(() => window.syncPath());
|
||||||
});
|
});
|
||||||
|
|
||||||
window.vueRouter = router;
|
window.vueRouter = router;
|
||||||
|
@ -1,21 +1,19 @@
|
|||||||
import Vue from 'vue';
|
import { createApp } from 'vue';
|
||||||
|
import VueRouter from 'vue-router';
|
||||||
import DemoBlock from './components/DemoBlock';
|
import DemoBlock from './components/DemoBlock';
|
||||||
import DemoSection from './components/DemoSection';
|
import DemoSection from './components/DemoSection';
|
||||||
import { router } from './router';
|
import { router } from './router';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
import '@vant/touch-emulator';
|
import '@vant/touch-emulator';
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
|
||||||
Vue.config.productionTip = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vue.component(DemoBlock.name, DemoBlock);
|
|
||||||
Vue.component(DemoSection.name, DemoSection);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
new Vue({
|
const app = createApp({
|
||||||
el: '#app',
|
render: (h) => h(App),
|
||||||
render: h => h(App),
|
|
||||||
router,
|
router,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(VueRouter);
|
||||||
|
app.component(DemoBlock.name, DemoBlock);
|
||||||
|
app.component(DemoSection.name, DemoSection);
|
||||||
|
app.mount('#app');
|
||||||
}, 0);
|
}, 0);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import Vue from 'vue';
|
import { nextTick } from 'vue';
|
||||||
import VueRouter from 'vue-router';
|
import VueRouter from 'vue-router';
|
||||||
import DemoHome from './components/DemoHome';
|
import DemoHome from './components/DemoHome';
|
||||||
import { decamelize } from '../common';
|
import { decamelize } from '../common';
|
||||||
@ -29,10 +29,10 @@ function getRoutes() {
|
|||||||
if (langs.length) {
|
if (langs.length) {
|
||||||
routes.push({
|
routes.push({
|
||||||
path: '*',
|
path: '*',
|
||||||
redirect: route => `/${getLangFromRoute(route)}/`,
|
redirect: (route) => `/${getLangFromRoute(route)}/`,
|
||||||
});
|
});
|
||||||
|
|
||||||
langs.forEach(lang => {
|
langs.forEach((lang) => {
|
||||||
routes.push({
|
routes.push({
|
||||||
path: `/${lang}`,
|
path: `/${lang}`,
|
||||||
component: DemoHome,
|
component: DemoHome,
|
||||||
@ -51,11 +51,11 @@ function getRoutes() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
names.forEach(name => {
|
names.forEach((name) => {
|
||||||
const component = decamelize(name);
|
const component = decamelize(name);
|
||||||
|
|
||||||
if (langs.length) {
|
if (langs.length) {
|
||||||
langs.forEach(lang => {
|
langs.forEach((lang) => {
|
||||||
routes.push({
|
routes.push({
|
||||||
name: `${lang}/${component}`,
|
name: `${lang}/${component}`,
|
||||||
path: `/${lang}/${component}`,
|
path: `/${lang}/${component}`,
|
||||||
@ -81,8 +81,6 @@ function getRoutes() {
|
|||||||
return routes;
|
return routes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vue.use(VueRouter);
|
|
||||||
|
|
||||||
export const router = new VueRouter({
|
export const router = new VueRouter({
|
||||||
mode: 'hash',
|
mode: 'hash',
|
||||||
routes: getRoutes(),
|
routes: getRoutes(),
|
||||||
@ -91,7 +89,7 @@ export const router = new VueRouter({
|
|||||||
|
|
||||||
router.afterEach(() => {
|
router.afterEach(() => {
|
||||||
if (!router.currentRoute.redirectedFrom) {
|
if (!router.currentRoute.redirectedFrom) {
|
||||||
Vue.nextTick(window.syncPath);
|
nextTick(window.syncPath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user