vue3构建项目流程总结

1.vite

npm init vite@latest 项目名称 -- --template vue-ts

2.package.json
“dependencies”: {
“@element-plus/icons-vue”: “^2.0.6”,
“axios”: “^0.27.2”,
“dayjs”: “^1.11.3”,
“element-plus”: “^2.2.6”,
“jwt-decode”: “^3.1.2”,
“pinia”: “^2.0.14”,
“pinia-plugin-persist”: “^1.0.0”,
“ts-md5”: “^1.2.11”,
“vue”: “^3.2.25”,
“vue-router”: “^4.0.16”,
“wangeditor”: “^4.7.15”
}

3.main.ts

import {
    createApp } from 'vue'
import App from './App.vue'
//导入我们的路由文件
import Router from  './router/index'
//导入store
import store from './store/index'
//导入饿了么UI组件
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
   
  app.component(key, component)
}
//实用路由
app.use(Router)
//使用store
app.use(store);
//使用饿了么UI组件
app.use(ElementPlus)
app.mount('#app')

4.http
index.ts

import axios, {
   
  AxiosRequestConfig,
  AxiosRequestHeaders,
  AxiosResponse,
} from "axios";
import {
    ElMessage, ElLoading } from "element-plus";
import {
    storeToRefs } from "pinia";
import appStore from "@/store/appStore";
let {
     token } = storeToRefs(appStore());

const state = {
   
  ok: 0,//请求成功状态码
  401:"ERR_BAD_REQUEST"
};

//返回数据规则
interface IResponseData<T> {
   
  status: number;
  message?: string;
  data: T;
  code: string;
}

//请求默认配置规则
type TOption = {
   
  baseURL: string;
  timeout: number;
};

//默认配置
const config = {
   
  baseURL: "",
  timeout: 30 * 1000,
  withCredentials: true,
};


let loading:any = null;

class Http {
   
  service: any;
  constructor(config: TOption) {
   
    //实例化请求配置
    this.service = axios.create(config);

    //请求拦截
    this.service.interceptors.request.use(
      (config: AxiosRequestConfig
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

great-sun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值