- 首先github上创建仓库 方便代码管理
- 我这边使用git的工具sourcetree ,先把项目拉取到本地
- 创建vue项目,这个就不说太多了
创建好了基本就是这个样子了
- 安装常用插件(axios,ui插件,echarts…什么的)
这些网上都有,直接查一下,npm安装就好了
这是我这个项目用到的,在package.json中
"dependencies": {
"axios": "^0.19.0",
"babel-polyfill": "^6.26.0",
"core-js": "^3.4.3",
"echarts": "^4.6.0",
"view-design": "^4.0.2",
"vue": "^2.6.10",
"vue-axios": "^2.1.5",
"vue-cropper": "^0.4.9",
"vue-router": "^3.1.3",
"vuex": "^3.1.2"
},
- 创建项目组件
先构建好项目基础组件(login…),公共组件什么的(自定义的弹框什么的…),后面根据需求再加
- 配置下路由
// login什么的就直接引入了,剩下的都是路由懒加载(优化点是点)
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Login from "../components/login/Login";
Vue.use(VueRouter);
import RouterTo from "../components/login/RouterTo";
const routes = [
{
path: '/',
name: 'login',
component: Login,
meta: {
id: '1-1',
},
},
{
path: '/router-to',
name: 'router-to',
component: RouterTo,
},
{
path: '/home',
name: 'home',
redirect: '/create-work-card',
component: Home,
children:[
{path: '/menu', name: 'menu' , meta: {id: '3-1'}, component: () => import ("../components/manage-system/Menu")},
{path: '/role', name: 'role' , meta: {id: '3-2'}, component: () => import ("../components/manage-system/Role")},
{path: '/user', name: 'user' , meta: {id: '3-3'}, component: () => import ("../components/manage-system/User")},
{path: '/dept', name: 'dept' , meta: {id: '3-4'}, component: () => import ("../components/manage-system/Dept")},
]
},
- 封装axios,axios拦截,接口管理
具体使用请参考axios封装及使用 https://blog.csdn.net/weixin_46096120/article/details/104767633
// 我创建了个工具文件夹,request,主要对axios做配置,tools对接口做下封装
import axios from 'axios'
const service = axios.create({
headers: {
'Content-type': 'application,json'
},
timeout: 5000, // request timeout
withCredentials: true
});
service.interceptors.request.use(
config => {
// return Promise.reject()
return config
}, error => {
return Promise.reject(error)
}
) ;
service.interceptors.response.use(
response => {
return response
}, error => {
Message.error('服务器异常');
return Promise.reject(error)
}
);
export default service
import requestAxios from './camera-request'
import qs from 'querystring'
export const createScenes = (data) => {
return requestAxios({
url: '/api/v1/scenes',
method: 'POST',
data:data,
})
};
export const getScenes = () => {
return requestAxios({
url: '/api/v1/scenes',
method: 'GET',
})
};
export const deleteScenes = (data) => {
return requestAxios({
url: `/api/v1/scenes/${data}`,
method: 'DELETE',
})
};
- 基本配置做完了,接下来就可以愉快的开发了!