# vue3-ts-template-h5 **Repository Path**: sync-github/vue3-ts-template-h5 ## Basic Information - **Project Name**: vue3-ts-template-h5 - **Description**: Vue3.0 + Typescript + Sass + Vant 移动端 - **Primary Language**: TypeScript - **License**: Not specified - **Default Branch**: master - **Homepage**: https://github.com/weizhanzhan/vue3-ts-template-h5 - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 1 - **Created**: 2021-11-05 - **Last Updated**: 2022-05-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README > 遇到安装依赖启动报错的升级一下Typescript >npm install typescript@4.5.3 --dev # vue3-ts-template-h5 ![vue3](https://github.com/weizhanzhan/vue3-ts-template-h5/blob/master/src/assets/images/vue3.png) [访问一](https://www.weizhan.site) [访问二](https://vue3-ts-template-h5.vercel.app) ## Vue3.0 + Typescript 初体验,打造h5,webapp移动端模板,开箱即用 📖 `Vue3.0` 相关文档: | 相关库名称 | 在线地址 🔗 | | --------- | ----- | | Vue3.0 官方文档 | 链接 | | Vue3.0 中文文档 | 链接 国内链接| | Composition-API手册 | 链接 | | Vue3.0 源码学习 | 链接 | | Vue-Router 官方文档 | 链接 | | Vuex4.0(目前在 beta 阶段) | Github | [demo浏览](https://vue3-ts-template-h5.vercel.app) ## 目录 - [基础搭建](#基础搭建) - [Vue3.0新特性与改动](#vue3的新特性和改动) - [新颖的CompositionApi](#CompositionApi) - [Axios配置及接口数据类型定义](#Axios配置及接口数据类型定义) - [关于Vue3中使用Typescript的注意点](#关于Vue3中使用Typescript的注意点) - [Vant配置](#vant配置) - [Vant主题修改](#vant主题色) - [关于样式穿透](#关于样式穿透) - [浏览器样式重置](#浏览器样式重置) - [移动端1px边框](#移动端1px边框) - [Vue3.0中Vuex的配置与使用以及替代方案](#vuex的配置与使用) - [Vue3.0路由配置和缓存](#vue路由配置和缓存) - [tsconfig配置](#tsconfig配置) - [语法检测自动格式代码](#语法检测自动格式代码) - [发布&部署](#发布&部署) - [关于我](#关于我) - [感谢](#感谢) ## 基础搭建 - vue3配置 ```sh # 1.安装vue-cli next npm install --global @vue/cli@next # 2.创建项目,创建选择模板的时候,选择“Manually select features",下面有我的options,仅供参考 vue create my-project-name # 如果已经有了一个cli项目不是TypeScript,可以增加一个cli的插件 vue add typescript ``` My Vue CLI Option >Vue CLI v4.5.4 >1. Please pick a preset: **Manually select features** >2. Check the features needed for your project: Choose **Vue version, Babel, TS, Router, Vuex, CSS Pre-processors, Linter** >3. Choose a version of Vue.js that you want to start the project **with 3.x (Preview)** >4. Use class-style component syntax? **Yes** >5. Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)? **Yes** >6. Use history mode for router? (Requires proper server setup for index fallback in production) **Yes** >7. Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): **Sass/SCSS (with node-sass)** >8. Pick a linter / formatter config: **Prettier** >9. Pick additional lint features: **Lint on save** >10. Where do you prefer placing config for Babel, ESLint, etc.? (Use arrow keys) **In dedicated config files** # vue3的新特性和改动 ## 1.v-model ### 2.x语法 在 2.x 中,在组件上使用 v-model 相当于绑定 `value` prop 和 `input` 事件: ```html ``` 使用`v-bind:sync` vue是单向数据流,为了对prop进行"双向绑定",可以是用sync来实现 ```html ``` 子组件内通过下面方式通知父父组件 ```js this.$emit('update:title',value) ``` ### 3.x语法 在3.x中自定义组件的`v-model`,是传递了`modelValue`prop并接受抛出的`update:modelValue`事件,和sync很像 ```html ``` `v-model`参数 若需要更改 `model` 名称,而不是更改组件内的 `model` 选项,而是将一个 `argument` 传递给 `model` ```html ``` 因此我们直接可以2.x的sync改成现在这种写法 ```html ``` 并且一个子组件我们可以写多个v-model ```html ``` ## v-for v-for的变动最主要体现在`key`上面,我们在使用`