這是《基於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