搭建步骤 创建vite-vue项目模板 1 2 3 4 5 6 7 8 9 10 11 12 npm init @vitejs/app m-vvv3 --template vue-ts npx: 5 安装成功,用时 4.119 秒 Scaffolding project in C:\*\m-vvv3... Done. Now run: cd m-vvv3 npm install (or `yarn`) npm run dev (or `yarn dev`)
安装vant3
vue-router 1 2 npm install vue-router@4 --save
router/index.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import { createRouter, createWebHashHistory } from 'vue-router' ; import Home from '../views/Home.vue' import About from '../views/About.vue' const routes: Array<any> = [ { path: '/' , name: 'Home' , component: Home }, { path: '/about' , name: 'About' , component: About } ] const router = createRouter({ history : createWebHashHistory(), routes })export default router
main.ts
1 2 3 4 5 6 import { createApp } from 'vue' import App from './App.vue' import router from './router/index' import 'vant/lib/index.css' ; createApp(App).use(router).mount('#app' )
vuex 1 2 3 4 5 npm install vuex@next --save
store/index.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 import { createStore, createLogger } from 'vuex' import * as getters from './getters.ts' import * as mutations from './mutations.ts' import * as actions from './actions.ts' import example from './modules/example.ts' const debug = process.env.NODE_ENV !== 'production' const store = createStore({ state () { return { count: 10 } }, getters: { double(state) { return state.count * 2 } }, mutations, actions, modules: { example }, strict: debug })export default store
Sass
生命周期 Option-API VS Compisition-API
1 2 3 4 5 6 7 8 9 beforeCreate -> use setup() created -> use setup() beforeMount -> onBeforeMount mounted -> onMounted beforeUpdate -> onBeforeUpdate updated -> onUpdated beforeDestroy -> onBeforeUnmount destroyed -> onUnmounted errorCaptured -> onErrorCaptured
填坑记录
npm run dev报错 v2.0.0-beta.12、v2.0.0-beta.22在windows 10环境下会报错,使用beta.21版本
相关资料 https://vitejs.dev/guide https://v3.cn.vuejs.org/ https://next.router.vuejs.org/ https://next.vuex.vuejs.org/ https://www.jianshu.com/p/0ebd56cb22d2 https://www.cnblogs.com/QQPrincekin/p/13802421.html https://github.com/vue3/vue3-router4-typescript