使用vue-cli3+typescript构建tsx开发模板的步骤分享
PDF格式 | 114KB |
更新于2024-08-30
| 198 浏览量 | 举报
基于 Vue CLI 3+TypeScript 的 TSX 开发模板搭建过程分享
本文将详细介绍使用 Vue CLI 3+TypeScript 创建基于 TS 的模板,并将模板方式改成 TSX 的方式,借助 vue-tsx-support 库。
知识点一:使用 Vue CLI 3+ 创建基于 TS 的模板
使用 Vue CLI 3+ 可以快速创建一个基于 TypeScript 的模板,命令如下:
```
vue create my-project
```
这将创建一个名为 my-project 的项目,并使用 TypeScript 作为默认语言。
知识点二:安装 vue-tsx-support 库
为了将模板方式改成 TSX 的方式,我们需要安装 vue-tsx-support 库,命令如下:
```
npm install vue-tsx-support --save
```
或
```
yarn add vue-tsx-support
```
安装结束后,我们需要对我们的文件做一些小改动。
知识点三:配置 main.ts 文件
在主入口文件 main.ts 中,我们需要引入 vue-tsx-support 库,代码如下:
```
import * as tsx from 'vue-tsx-support';
```
知识点四:删除 src/shims-tsx.d.ts 文件
为了避免和 vue-tsx-support/enable-check 声明重复冲突,我们需要删除 src/shims-tsx.d.ts 文件。
知识点五:配置 vue.config.js 文件
在 vue.config.js 文件中,我们需要在 configureWebpack 属性下增加一项 resolve,代码如下:
```
module.exports = {
// ...
configureWebpack: {
resolve: {
extensions: ['.js', '.vue', '.json', '.ts', '.tsx'] // 加入 ts 和 tsx
}
}
}
```
知识点六:创建 TSX 文件
现在,我们可以在 /components 下新建一个文件 button.tsx,代码如下:
```
import { Component, Prop } from 'vue-property-decorator';
import * as tsx from 'vue-tsx-support';
interface ButtonClick {
(value: string): void
}
interface ButtonProps {
text: string;
btnClick?: ButtonClick
}
@Component
export default class ZButton extends tsx.Component<ButtonProps> {
// ...
}
```
这样,我们就可以开始开发基于 TSX 的 Vue 项目了。
相关推荐
![filetype](https://img-home.csdnimg.cn/images/20241231044930.png)
![filetype](https://img-home.csdnimg.cn/images/20241231045053.png)
![filetype](https://img-home.csdnimg.cn/images/20241231044930.png)
![filetype](https://img-home.csdnimg.cn/images/20241231044930.png)
![filetype](https://img-home.csdnimg.cn/images/20241231044930.png)
![filetype](https://img-home.csdnimg.cn/images/20241231045053.png)
![filetype](https://img-home.csdnimg.cn/images/20241231044901.png)
![filetype](https://img-home.csdnimg.cn/images/20241231045053.png)
![filetype](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://profile-avatar.csdnimg.cn/default.jpg!1)
weixin_38731075
- 粉丝: 1
最新资源
- Akij-Group销售代表管理系统:进行中的技术创新
- Python快速入门教程,基础语法到Django框架
- STM32F0红外接收技术在物联网中的应用
- 多种输入法词库转换工具:绿色版使用指南
- STM32系列IC的LQFP封装全集合
- Matlab Interface开发:实现未截断牛顿时间算法
- GB2312标准宋粗字体文件压缩包详解
- HdfsExplorer开源客户端工具的C#实现
- 乔·苏米斯网页设计作品集解析
- Apache Tomcat 8.0.9 压缩包使用指南
- Neo4j 2.1.2版本的Windows运行包下载
- MbrFix:在Windows下恢复MBR以删除Linux系统的工具
- MATLAB符号表达式向量化转换技术解析
- 解决IE Applet小程序显示问题的JAVA插件
- 搭建简易Spring框架开发环境教程
- 地震波地下传播模拟的波动方程正演程序