这是《基于nuxt和iview搭建OM后台管理系统实践》这一个系列文章的目录,大体思路以下:html
清明节后回到武汉,在周例会上,项目经理提出要开发一个我们app的后台管理系统(OM系统),预估两周时间开发完并上线,而且要实现先后端分离,最终在通过短暂的技术选型和苦逼开发后终于延后几天并上线了。写下这篇文章记录一下开发(踩坑)过程。前端
由于是公司的项目,后台模块分布的图片只存在于个人有道云笔记,后续会根据这些模块封装一些公共组件出来。vue
// 文件 layouts/nav.vue <template> <div> <nuxt/> <leftNav/> <topNav/> </div> </template> <script> // import MyFooter from '~/components/Footer.vue' import leftNav from '~/components/leftNav.vue'; import topNav from '~/components/topNav.vue'; export default { components: { leftNav, topNav } } </script> <style> </style>
// 文件 pages/index.vue <script> export default { layout: "nav",//此处引用layout的nav布局文件 } </script>
//文件 components/left-nav.vue goto(obj) { let path = ""; // this.$store.commit("upMenuName", obj); //更新menuName setStore('menuName',obj); this.menuName = getStore('menuName'); this.$store.state.menuList.forEach(element => { element.list.forEach(el => { if (el.id == obj) { path = el.path; } }); }); this.$router.push(path); // window.location = path; }
//文件 plugins/axios.js import axios from 'axios'; import Vue from 'vue'; import * as utils from '../lib/utils'; // import {Spin,Notice} from 'iview'; // import router from '' let options = {} // The server-side needs a full url to works if (process.server) { // options.baseURL = `http://${process.env.HOST || 'localhost'}:${process.env.PORT || 3000}` axios.defaults.baseURL = `http://${process.env.HOST || 'localhost'}:${process.env.PORT || 3000}/api` } axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded'; axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'; // axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; axios.defaults.withCredentials = true; axios.defaults.timeout = 5000; //请求以前 axios.interceptors.request.use((config)=>{ // console.log(config) // Spin.show(); return config; }); //登录失效跳转登陆页面 axios.interceptors.response.use( response => { console.log('-------axiosResponse---------') // console.log(response); // Spin.hide(); return response; }, error => { console.log('-------axiosError---------'); console.log(error.response.status); if (error.response.status) { switch (error.response.status) { case 401: // if (process.server){ utils.clearLocalStorage(); console.log(window.location) window.location.href= '/login?url'+window.location.pathname // } } } // Spin.hide(); // Notice.error({ // title: '舒适提示:', // desc: '网络请求失败,请稍后再试' // }); // console.log(error.response.status); return Promise.reject(error.response.data) } ); export default axios;
<script> import axios from "~plugins/axios"; export default { methods:{ loadData(){ axios.get(urls.api, { params: this.param }) .then(res => { //请求成功回调 }) .catch(error => { //请求失败 }); } } </script>
vue、nuxt、iview、axios、vuex、v-charts、proxy、nginx
如下列了一些开发过程当中所用到的文档和ui组件ios