From c005f41cdaa5ec9df57de3aeb0609a6a59ac392b Mon Sep 17 00:00:00 2001 From: weixin_46115723 Date: Wed, 13 Mar 2024 14:35:00 +0800 Subject: [PATCH] Wed Mar 13 14:35:00 CST 2024 inscode --- package.json | 4 +++- src/App.vue | 48 ++++++++++++++++++++++++++++++++++++----- src/main.js | 12 +++++++++-- src/router/index.js | 23 ++++++++++++++++++++ src/stores/counter.js | 12 +++++++++++ src/views/AboutView.vue | 15 +++++++++++++ src/views/HomeView.vue | 9 ++++++++ vite.config.js | 26 ++++++++++++++++++---- 8 files changed, 137 insertions(+), 12 deletions(-) create mode 100644 src/router/index.js create mode 100644 src/stores/counter.js create mode 100644 src/views/AboutView.vue create mode 100644 src/views/HomeView.vue diff --git a/package.json b/package.json index 6944891..1935bf0 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,9 @@ "dependencies": { "element-plus": "^2.5.6", "guess": "^1.0.2", - "vue": "^3.2.37" + "pinia": "^2.1.7", + "vue": "^3.2.37", + "vue-router": "^4.3.0" }, "devDependencies": { "@vitejs/plugin-vue": "^3.0.1", diff --git a/src/App.vue b/src/App.vue index 633a5df..e864195 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,25 +1,29 @@ diff --git a/src/main.js b/src/main.js index 90e6400..5dcad83 100644 --- a/src/main.js +++ b/src/main.js @@ -1,6 +1,14 @@ +import './assets/main.css' + import { createApp } from 'vue' +import { createPinia } from 'pinia' + import App from './App.vue' +import router from './router' -import './assets/main.css' +const app = createApp(App) + +app.use(createPinia()) +app.use(router) -createApp(App).mount('#app') +app.mount('#app') diff --git a/src/router/index.js b/src/router/index.js new file mode 100644 index 0000000..6114818 --- /dev/null +++ b/src/router/index.js @@ -0,0 +1,23 @@ +import { createRouter, createWebHistory } from 'vue-router' +import HomeView from '../views/HomeView.vue' + +const router = createRouter({ + history: createWebHistory(import.meta.env.BASE_URL), + routes: [ + { + path: '/', + name: 'home', + component: HomeView + }, + { + path: '/about', + name: 'about', + // route level code-splitting + // this generates a separate chunk (About.[hash].js) for this route + // which is lazy-loaded when the route is visited. + component: () => import('../views/AboutView.vue') + } + ] +}) + +export default router diff --git a/src/stores/counter.js b/src/stores/counter.js new file mode 100644 index 0000000..89bc879 --- /dev/null +++ b/src/stores/counter.js @@ -0,0 +1,12 @@ +import { ref, computed } from 'vue' +import { defineStore } from 'pinia' + +export const useCounterStore = defineStore('counter', () => { + const count = ref(0) + const doubleCount = computed(() => count.value * 2) + function increment() { + count.value++ + } + + return { count, doubleCount, increment } +}) diff --git a/src/views/AboutView.vue b/src/views/AboutView.vue new file mode 100644 index 0000000..6ed9f76 --- /dev/null +++ b/src/views/AboutView.vue @@ -0,0 +1,15 @@ + + + diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue new file mode 100644 index 0000000..0ba7c74 --- /dev/null +++ b/src/views/HomeView.vue @@ -0,0 +1,9 @@ + + + diff --git a/vite.config.js b/vite.config.js index 4ad898d..4d9f38e 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,10 +1,28 @@ +// import { defineConfig } from 'vite' +// import vue from '@vitejs/plugin-vue' + +// // https://vitejs.dev/config/ +// export default defineConfig({ +// server: { +// host: true +// }, +// plugins: [vue()] +// }) + + +import { fileURLToPath, URL } from 'node:url' + import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' // https://vitejs.dev/config/ export default defineConfig({ - server: { - host: true - }, - plugins: [vue()] + plugins: [ + vue(), + ], + resolve: { + alias: { + '@': fileURLToPath(new URL('./src', import.meta.url)) + } + } }) -- GitLab