1、修改vite.config.ts 2、修改tsconfig.app.json (ts) 在compilerOptions中添加下面的最后2项:“baseUrl"和"paths” 添加下面代码 "baseUrl": "./", "paths": { "@/*": [ "src/*" ] } 13.项目结构,在src文件夹下,添加api,router ,store,views文件夹 配置vite-env.d.ts 文件 /// <reference ...
vite 建立的 vue3 项目,通过import.meta.env获取开发环境的变量配置 若一定要在 vite 建立的项目中使用process.env, 先执行npm i --save-dev @types/node,然后在vite.config.ts文件, 添加下面的define内容。 import{ defineConfig }from'vite'importvuefrom'@vitejs/plugin-vue'// https://vitejs.dev/config...
2,安装一下vue-router,npm install vue-router; mian.ts文件里面use一下路由: 3,router文件下的index.ts代码: 4,routes文件下,index.ts代码: homeRoutse是home路由模块下的,是其子路由,testRoutes是并列于home模块的路由。 要根据自己项目的情况配置。 5,单独模块路由的代码: 6,有报红,是文件路径@的问题和t...
颜色Store 新建src/store/color.ts,内容如下。主要是有一个primary主颜色的属性并且默认是element-plus的主颜色,持久化数据,预定义了7个颜色,primaryChange是颜色选择器实时改变更新网页属性的回调,primarySave是颜色选择器确定颜色时的回调。 import{ defineStore }from'pinia'constuseColorStore =defineStore('appcolor...
vite 是基于esmodule的 所以type="module" 新建app.vue模板 <template>启动测试</template> 新建main.ts import{createApp}from'vue'importAppfrom'./app.vue'constapp =createApp(App) app.mount('#app') 此时会发现编译器会提示个错误:找不到模块“./app.vue”或其相应的类型声明 因为直接引入.vue...
VITE_BASE_API='http://localhost:8081/' 创建文件 .env.production(生产环境) VITE_BASE_API=http://localhost:9999/' vite.config.ts // vite.config.ts import vue from '@vitejs/plugin-vue'; // loadEnv import { UserConfig, ConfigEnv, loadEnv, defineConfig } from 'vite'; ...
@vitejs/plugin-vue 会默认加载examples下的index.html 新建index.html 注意:vite 是基于esmodule的 所以type="module" 新建app.vue模板 新建main.ts 此时会发现编译器会提示个错误:找不到模块“./app.vue”或其相应的类型声明 因为直接引入.vue文件 TS会找不到对应的类型声明;所以需要新建typings(命名没有明确...
base.ts: import axios from 'axios' const request = (option: any) => { return axios(option) } function Service(value: { namespace?: string; url?: string; prefix?: string }) { return function (target: any) { target.prototype.namespace = value.namespace ...
{ "env": { "browser": true, "es2021": true, "node": true }, "extends": [ "plugin:vue/vue3-essential", "eslint:recommended", "standard", "plugin:prettier/recommended" ], // vue-eslint-parser 用来解析.vue后缀文件,使得eslint能解析<template>标签中的内容,而 @typescript-eslint/...
一、创建一个Vite+Vue3+TS的项目 二、eslint配置 eslint中文官网:http://eslint.cn/ ESLint最初是由Nicholas C.Zakas 于2013年6月创建的开源项目。它的目标是提供一个插件化的iavascript代码检测工具 2.1. 安装eslint pnpm i eslint -D 2.2. 生成配置文件:.eslint.cjs ...