Skip to content
/ vben-axios Public template
forked from antfu-collective/vitesse

提取 vue-vben-admin 项目封装的 axios 请求库,方便在新项目中使用

License

Notifications You must be signed in to change notification settings

lessroc/vben-axios

 
 

Repository files navigation

Vitesse - Opinionated Vite Starter Template

Mocking up web app with Vitesse(speed)


Live Demo


Note: This template is created during the early transition of Vue 3 and Vite. At this moment, if you are seeking for better Vue developer experience and more consistent maintenance, we recommend using Nuxt 3 instead (it also works perfectly with SPA or SSG as needed). This template still serves as a reference, but expect slower updates.


English | 简体中文


Vben Axios

  • Extract the axios request library encapsulated by vue-vben-admin and integrate it into the vitesse template for easy use in other projects

Features

  • The configuration items are extremely rich, adding flexible custom configuration and high encapsulation
  • Specific reference http/axios
function createAxios(opt?: Partial<CreateAxiosOptions>) {
  return new VAxios(
    // 深度合并
    deepMerge(
      {
        // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#authentication_schemes
        // authentication schemes,e.g: Bearer
        // authenticationScheme: 'Bearer',
        authenticationScheme: '',
        timeout: 10 * 1000,
        // 基础接口地址
        // baseURL: globSetting.apiUrl,

        headers: { 'Content-Type': ContentTypeEnum.JSON },
        // 如果是form-data格式
        // headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED },
        // 数据处理方式
        transform: clone(transform),
        // 配置项,下面的选项都可以在独立的接口请求中覆盖
        requestOptions: {
          // 默认将prefix 添加到url
          joinPrefix: true,
          // 是否返回原生响应头 比如:需要获取响应头时使用该属性
          isReturnNativeResponse: false,
          // 需要对返回数据进行处理
          isTransformResponse: true,
          // post请求的时候添加参数到url
          joinParamsToUrl: false,
          // 格式化提交参数时间
          formatDate: true,
          // 消息提示类型
          errorMessageMode: 'message',
          // 接口地址
          apiUrl: globSetting.apiUrl,
          // 接口拼接地址
          urlPrefix,
          // 是否加入时间戳
          joinTime: true,
          // 忽略重复请求
          ignoreCancelToken: true,
          // 是否携带token
          withToken: true,
          retryRequest: {
            isOpenRetry: true,
            count: 5,
            waitTime: 100,
          },
        },
      },
      opt || {},
    ),
  )
}

Features


Pre-packed

UI Frameworks

  • UnoCSS - The instant on-demand atomic CSS engine.

Icons

Plugins

Coding Style

Dev tools

Variations

As this template is strongly opinionated, the following provides a curated list for community-maintained variations with different preferences and feature sets. Check them out as well. PR to add yours is also welcome!

Official
Community

Try it now!

Vitesse requires Node >=14.18

GitHub Template

Create a repo from this template on GitHub.

Clone to local

If you prefer to do it manually with the cleaner git history

npx degit antfu/vitesse my-vitesse-app
cd my-vitesse-app
pnpm i # If you don't have pnpm installed, run: npm install -g pnpm

Checklist

When you use this template, try follow the checklist to update your info properly

  • Change the author name in LICENSE
  • Change the title in App.vue
  • Change the hostname in vite.config.ts
  • Change the favicon in public
  • Remove the .github folder which contains the funding info
  • Clean up the READMEs and remove routes

And, enjoy :)

Usage

Development

Just run and visit http://localhost:3333

pnpm dev

Build

To build the App, run

pnpm build

And you will see the generated file in dist that ready to be served.

Deploy on Netlify

Go to Netlify and select your clone, OK along the way, and your App will be live in a minute.

Docker Production Build

First, build the vitesse image by opening the terminal in the project's root directory.

docker buildx build . -t vitesse:latest

Run the image and specify port mapping with the -p flag.

docker run --rm -it -p 8080:80 vitesse:latest

Why

I have created several Vite apps recently. Setting the configs up is kinda the bottleneck for me to make the ideas simply come true within a very short time.

So I made this starter template for myself to create apps more easily, along with some good practices that I have learned from making those apps. It's strongly opinionated, but feel free to tweak it or even maintain your own forks. (see community maintained variation forks)

About

提取 vue-vben-admin 项目封装的 axios 请求库,方便在新项目中使用

Topics

Resources

License

Stars

Watchers

Forks

Languages

  • TypeScript 85.1%
  • Vue 11.4%
  • HTML 1.6%
  • CSS 1.2%
  • Dockerfile 0.7%