Skip to content

基于vue3的基础开发模板,包含状态管理、网络请求、路由拦截、国际化、Token无感刷新、接口签名等常用功能。UI框架可根据自己的需求集成(附element plus、vant集成文档)

License

Notifications You must be signed in to change notification settings

cshaptx4869/vue3-base-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vue3-base-template

This template should help get you started developing with Vue 3 in Vite.

Recommended IDE Setup

VSCode + Volar (and disable Vetur).

Type Support for .vue Imports in TS

TypeScript cannot handle type information for .vue imports by default, so we replace the tsc CLI with vue-tsc for type checking. In editors, we need Volar to make the TypeScript language service aware of .vue types.

Customize configuration

See Vite Configuration Reference.

Project Setup

pnpm install

Compile and Hot-Reload for Development

pnpm dev

Type-Check, Compile and Minify for Production

pnpm build

Integrated UI Framework

Element Plus

Install element plus

pnpm install element-plus

Automatically import components

pnpm add unplugin-vue-components unplugin-auto-import -D
// vite.config.ts
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default {
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
};

Usage

<template>
  <el-button>Default</el-button>
</template>
<script setup>
  ElMessage.error('No need to import ElMessage');
</script>

Vant

Install vant

pnpm add vant

Automatically import components

pnpm add @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D
// vite.config.ts
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from '@vant/auto-import-resolver';

export default {
  plugins: [
    vue(),
    AutoImport({
      resolvers: [VantResolver()],
    }),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
};

Viewport layout

pnpm add postcss-px-to-viewport-8-plugin -D
// vite.config.ts
import vue from "@vitejs/plugin-vue";
import postcsspxtoviewport8plugin from "postcss-px-to-viewport-8-plugin";

export default {
  plugins: [vue()],
  css: {
    postcss: {
      plugins: [
        postcsspxtoviewport8plugin({
          unitToConvert: "px",
          viewportWidth: (file) => {
            // Design draft width
            let num = 750;
            if (file.indexOf("vant") !== -1) {
              // console.log(file);
              num = 375;
            }
            return num;
          },
        }),
      ],
    },
  },
};

Usage

<template>
  <van-button type="primary" />
</template>
<script setup>
  showToast('No need to import showToast');
</script>

About

基于vue3的基础开发模板,包含状态管理、网络请求、路由拦截、国际化、Token无感刷新、接口签名等常用功能。UI框架可根据自己的需求集成(附element plus、vant集成文档)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published