1 环境准备。
1.1 node 安装,设置镜像,创建工程项目。
安装node (官网下载安装,设置镜像)
cmd > npm config set registry http:
npm init @vitejs/app xxx
然后按提示操作。

1.2 一些配置设置.
npm install @types/node --save-dev
import path from "path";
export default defineConfig({
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
"com": path.resolve(__dirname, "src/components")
}
},
{
"compilerOptions": {
"paths": {
"@":["./src"]
}
},
2 项目插件安装
2.1 vue-router 安装
npm i vue-router@next
import {createRouter, createWebHashHistory, RouteRecordRaw} from "vue-router";
const routes:Array<RouteRecordRaw> = [
{
path: '/a',
name: 'a',
component:() => import('../page_demo/A.vue'),
},
{
path: '/b',
name: 'b',
component:() => import('../page_demo/B.vue'),
},
]
const router = createRouter({
history:createWebHashHistory(),
routes :routes
})
export default router
import router from "./router"
createApp(App).use(router).mount('#app')
<router-link to="/a">a.Vue</router-link>
<router-link to="/b">b.Vue</router-link>
<hr/>
<router-view></router-view>

2.2 vuex 安装及使用
npm i vuex@next
export interface iDemoState {
count:number,
name:string,
}
export const demoStore = {
namespaced: true,
state:{
count:111,
name:'hello demo'
},
mutations:{
incr(state:iDemoState) {
state.count ++;
}
},
getters:{
countDouble: (state:iDemo) => {
return state.count * 2;
},
},
}
import { InjectionKey } from 'vue'
import { createStore, useStore as baseUseStore, Store } from 'vuex'
import {demoStore, iDemoState} from "@/store/modules/demo.ts"
export interface RootState {
demoStore:iDemoState
}
export const key: InjectionKey<Store<RootState>> = Symbol()
export const store = createStore<RootState>({
modules:{
demoStore
}
})
export function useStore () {
return baseUseStore(key)
}
import {store, key} from '@/store';
createApp(App).use(store, key).mount('#app')
<template>A
<br/>
{{store.state.demoStore.name}}
<br/>
{{store.getters['demoStore/countDouble']}}
</template>
<script setup lang="ts">
import { useStore } from '@/store'
const store = useStore();
console.log("@@@",store)
</script>
2.3 安装 sass, 和element-plus
npm i sass-loader sass -D
npm install element-plus --save
https:
全局使用 icon
npm install @element-plus/icons
import * as ElIcons from '@element-plus/icons'
const app = createApp(App);
for (const name in ElIcons){
app.component(name,(ElIcons as any)[name])
}
3 代码例子下载。
示例代码下载