nelson
3 years ago
10 changed files with 93 additions and 41 deletions
@ -1,23 +0,0 @@ |
|||
import {createRouter,createWebHashHistory} from 'vue-router' |
|||
|
|||
import Home from '../views/tst/Home.vue' |
|||
|
|||
const routes = [ |
|||
{ |
|||
path: '/', |
|||
name: 'Home', |
|||
component: Home |
|||
}, |
|||
{ |
|||
path: '/about', |
|||
name: 'About', |
|||
component: () => import('../views/tst/About.vue') |
|||
} |
|||
] |
|||
|
|||
const router = createRouter({ |
|||
history: createWebHashHistory(), |
|||
routes |
|||
}) |
|||
|
|||
export default router |
@ -0,0 +1,24 @@ |
|||
import {createRouter, createWebHashHistory, RouteRecord, RouteRecordRaw} from 'vue-router' |
|||
|
|||
import Home from '../views/tst/Home.vue' |
|||
|
|||
const routes: Array<RouteRecordRaw> = |
|||
[ |
|||
{ |
|||
path: '/', |
|||
name: 'Home', |
|||
component: Home |
|||
}, |
|||
{ |
|||
path: '/about', |
|||
name: 'About', |
|||
component: () => import('../views/tst/About.vue') |
|||
} |
|||
] |
|||
|
|||
const router = createRouter({ |
|||
history: createWebHashHistory(), |
|||
routes |
|||
}) |
|||
|
|||
export default router |
@ -1,10 +0,0 @@ |
|||
import {createStore} from 'vuex' |
|||
|
|||
export default createStore({ |
|||
state: { |
|||
num: 0 |
|||
}, |
|||
mutations:{}, |
|||
actions:{}, |
|||
modules:{} |
|||
}) |
@ -0,0 +1,31 @@ |
|||
import {InjectionKey} from 'vue' |
|||
import {createStore, useStore as baseUseStore, Store} from 'vuex' |
|||
|
|||
// 为 store state 声明类型
|
|||
export interface State { |
|||
num: number |
|||
} |
|||
|
|||
// 定义 injection key
|
|||
export const key: InjectionKey<Store<State>> = Symbol() |
|||
|
|||
export const store = createStore<State>({ |
|||
state: { |
|||
num: 888 |
|||
}, |
|||
mutations: { |
|||
setNum(state: State, num: number) { |
|||
state.num = num |
|||
} |
|||
}, |
|||
getters: { |
|||
getNum(state: State) { |
|||
return state.num |
|||
} |
|||
} |
|||
}) |
|||
|
|||
// 定义自己的 `useStore` 组合式函数
|
|||
export function useStore() { |
|||
return baseUseStore(key) |
|||
} |
@ -1,7 +1,20 @@ |
|||
import { defineConfig } from 'vite' |
|||
import {defineConfig} from 'vite' |
|||
import vue from '@vitejs/plugin-vue' |
|||
|
|||
import {resolve} from "path"; |
|||
// https://vitejs.dev/config/
|
|||
export default defineConfig({ |
|||
plugins: [vue()] |
|||
plugins: [vue()], |
|||
server: { |
|||
host: '0.0.0.0', |
|||
port: 3000, |
|||
open: true |
|||
}, |
|||
resolve: { |
|||
alias: [ |
|||
{ |
|||
find: '@', |
|||
replacement: resolve(__dirname, 'src') |
|||
} |
|||
] |
|||
} |
|||
}) |
|||
|
Loading…
Reference in new issue