# shoping
**Repository Path**: tanzero/shoping
## Basic Information
- **Project Name**: shoping
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2024-12-17
- **Last Updated**: 2025-01-14
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# vue-rabbit项目
This template should help get you started developing with Vue 3 in Vite.
## Recommended IDE Setup推荐使用的IDE
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
## Customize configuration通用的配置
See [Vite Configuration Reference](https://vitejs.dev/config/).
## Project Setup 项目启动
```sh
npm install
```
### Compile and Hot-Reload for Development 项目运行
```sh
npm run dev
```
### Compile and Minify for Production
```sh
npm run build
```
### Lint with [ESLint](https://eslint.org/)代码开发规范使用ESLint
```sh
npm run lint
```
### 项目起步

### jsconfig.json配置别名路径
``` sh
{
"compilerOptions" : {
"baseUrl" : "./",
"paths" : {
"@/*":["src/*"]
}
}
}
```
### elementPlus引入
#### 1. 安装elementPlus和自动导入插件
``` sh
npm i elementPlus
npm install -D unplugin-vue-components unplugin-auto-import
```
#### 2. 配置自动按需导入
``` sh
// 引入插件
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig({
plugins: [
// 配置插件
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),
]
})
```
#### 3. 测试组件
``` sh
i am button
```
### 定制elementPlus主题
#### 1. 安装sass
```sh
npm i sass -D
```
#### 2. 准备定制化的样式文件
```sh
/* 只需要重写你需要的即可 */
@forward 'element-plus/theme-chalk/src/common/var.scss' with (
$colors: (
'primary': (
// 主色
'base': #27ba9b,
),
'success': (
// 成功色
'base': #1dc779,
),
'warning': (
// 警告色
'base': #ffb302,
),
'danger': (
// 危险色
'base': #e26237,
),
'error': (
// 错误色
'base': #cf4444,
),
)
)
```
#### 3. 自动导入配置
```sh
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
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'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
// 配置插件
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
// 配置elementPlus采用sass样式配色系统
resolvers: [ElementPlusResolver({ importStyle: 'sass' })],
}),
],
resolve: {
// 实际路径转换配置项
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
css: {
preprocessorOptions: {
scss: {
// 自动导入定制化样式文件进行样式覆盖
additionalData: `
@use "@/styles/element/index.scss" as *;
`,
}
}
}
})
```
### axios安装并简单封装
#### 1. 安装axios
```sh
npm i axios
```
#### 2. 基础配置
官方文档地址:
基础配置通常包括:
1. 实例化 - baseURL + timeout
2. 拦截器 - 携带token 401拦截等
```sh
import axios from 'axios'
// 创建axios实例
const http = axios.create({
baseURL: 'http://pcapi-xiaotuxian-front-devtest.itheima.net',
timeout: 5000
})
// axios请求拦截器
http.interceptors.request.use(config => {
return config
}, e => Promise.reject(e))
// axios响应式拦截器
http.interceptors.response.use(res => res.data, e => {
return Promise.reject(e)
})
export default http
```
#### 3. 封装请求函数并测试
``` sh
import http from '@/utils/http'
export function getCategoryAPI () {
return http({
url: 'home/category/head'
})
}
```
### 路由整体设计
#### 1. 路由设计
```sh
├── src
├── router
├── index.js
├── routes.js
├── views
├── Home.vue
├── Login.vue
├── NotFound.vue
├── Search.vue
├── Shop.vue
├── User.vue
```
#### 2. 路由配置
``` sh
// createRouter:创建router实例对象
// createW ebHistory:创建history模式的路由
import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
// path和component对应关系的位置
routes: [
{
path: '/',
component: Layout,
children: [
{
path: '',
component: Home
},
{
path: 'category',
component: Category
}
]
},
{
path: '/login',
component: Login
}
]
})
export default router
```sh
### 静态资源引入和Error Lens安装
#### scss变量自动导入
``` sh
$xtxColor: #27ba9b;
$helpColor: #e26237;
$sucColor: #1dc779;
$warnColor: #ffb302;
$priceColor: #cf4444;
```
``` sh
css: {
preprocessorOptions: {
scss: {
// 自动导入scss文件
additionalData: `
@use "@/styles/element/index.scss" as *;
@use "@/styles/var.scss" as *;
`,
}
}
}
```