From e44d3955fcc1067ee1280b3daaf55473244d0f48 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Sun, 19 Apr 2020 14:24:58 +0800 Subject: [PATCH] chore(cli): vue global api change --- packages/vant-cli/site/desktop/main.js | 13 ++++++------- packages/vant-cli/site/desktop/router.js | 10 ++++------ packages/vant-cli/site/mobile/main.js | 20 +++++++++----------- packages/vant-cli/site/mobile/router.js | 14 ++++++-------- 4 files changed, 25 insertions(+), 32 deletions(-) diff --git a/packages/vant-cli/site/desktop/main.js b/packages/vant-cli/site/desktop/main.js index 33c2a7708..a98350d67 100644 --- a/packages/vant-cli/site/desktop/main.js +++ b/packages/vant-cli/site/desktop/main.js @@ -1,19 +1,18 @@ -import Vue from 'vue'; +import { createApp } from 'vue'; import App from './App'; +import VueRouter from 'vue-router'; import { router } from './router'; import { scrollToAnchor } from './utils'; -if (process.env.NODE_ENV !== 'production') { - Vue.config.productionTip = false; -} - -new Vue({ +const app = createApp({ el: '#app', mounted() { if (this.$route.hash) { scrollToAnchor(this.$route.hash); } }, - render: h => h(App), + render: (h) => h(App), router, }); + +app.use(VueRouter); diff --git a/packages/vant-cli/site/desktop/router.js b/packages/vant-cli/site/desktop/router.js index a55e60a9a..4e1e387a0 100644 --- a/packages/vant-cli/site/desktop/router.js +++ b/packages/vant-cli/site/desktop/router.js @@ -1,4 +1,4 @@ -import Vue from 'vue'; +import { nextTick } from 'vue'; import VueRouter from 'vue-router'; import { isMobile, decamelize } from '../common'; import { config, documents } from 'site-desktop-shared'; @@ -48,7 +48,7 @@ function getRoutes() { if (locales) { routes.push({ path: '*', - redirect: route => `/${getLangFromRoute(route)}/`, + redirect: (route) => `/${getLangFromRoute(route)}/`, }); } else { routes.push({ @@ -66,7 +66,7 @@ function getRoutes() { }); } - names.forEach(name => { + names.forEach((name) => { const { component, lang } = parseName(name); if (component === 'home') { @@ -98,8 +98,6 @@ function getRoutes() { return routes; } -Vue.use(VueRouter); - export const router = new VueRouter({ mode: 'hash', routes: getRoutes(), @@ -113,7 +111,7 @@ export const router = new VueRouter({ }); router.afterEach(() => { - Vue.nextTick(() => window.syncPath()); + nextTick(() => window.syncPath()); }); window.vueRouter = router; diff --git a/packages/vant-cli/site/mobile/main.js b/packages/vant-cli/site/mobile/main.js index 94c80f4ae..c003a4bb9 100644 --- a/packages/vant-cli/site/mobile/main.js +++ b/packages/vant-cli/site/mobile/main.js @@ -1,21 +1,19 @@ -import Vue from 'vue'; +import { createApp } from 'vue'; +import VueRouter from 'vue-router'; import DemoBlock from './components/DemoBlock'; import DemoSection from './components/DemoSection'; import { router } from './router'; import App from './App'; 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(() => { - new Vue({ - el: '#app', - render: h => h(App), + const app = createApp({ + render: (h) => h(App), router, }); + + app.use(VueRouter); + app.component(DemoBlock.name, DemoBlock); + app.component(DemoSection.name, DemoSection); + app.mount('#app'); }, 0); diff --git a/packages/vant-cli/site/mobile/router.js b/packages/vant-cli/site/mobile/router.js index c3f1d9fa0..6d52571fb 100644 --- a/packages/vant-cli/site/mobile/router.js +++ b/packages/vant-cli/site/mobile/router.js @@ -1,4 +1,4 @@ -import Vue from 'vue'; +import { nextTick } from 'vue'; import VueRouter from 'vue-router'; import DemoHome from './components/DemoHome'; import { decamelize } from '../common'; @@ -29,10 +29,10 @@ function getRoutes() { if (langs.length) { routes.push({ path: '*', - redirect: route => `/${getLangFromRoute(route)}/`, + redirect: (route) => `/${getLangFromRoute(route)}/`, }); - langs.forEach(lang => { + langs.forEach((lang) => { routes.push({ path: `/${lang}`, component: DemoHome, @@ -51,11 +51,11 @@ function getRoutes() { }); } - names.forEach(name => { + names.forEach((name) => { const component = decamelize(name); if (langs.length) { - langs.forEach(lang => { + langs.forEach((lang) => { routes.push({ name: `${lang}/${component}`, path: `/${lang}/${component}`, @@ -81,8 +81,6 @@ function getRoutes() { return routes; } -Vue.use(VueRouter); - export const router = new VueRouter({ mode: 'hash', routes: getRoutes(), @@ -91,7 +89,7 @@ export const router = new VueRouter({ router.afterEach(() => { if (!router.currentRoute.redirectedFrom) { - Vue.nextTick(window.syncPath); + nextTick(window.syncPath); } });