在Vue中使用tsx语法进行项目构建
首先进行Vue项目的搭建,想必大家都会使用Vue-cli进行项目的搭建,这里我给大家说一下步骤:
- 使用
vue create vue-tsx
进行项目创建,我选择自定义进行创建
- 接着选择自己在项目中需要用到的一些插件和预处理器,这个我就不说明了,不明白的可以去查一查如何使用vue-cli进行创建vue项目。
- 删除views文件夹,删空components文件夹中的内容保留文件夹,删除App.vue文件。
- 接着修改router下的index.ts文件:
import Vue from "vue";
import VueRouter, {
RouteConfig } from "vue-router";
import Index from "../pages/index";
Vue.use(VueRouter);
const routes: Array<RouteConfig> = [
{
path: "/",
name: "index",
component: Index,
},
{
path