今天是個好日子,你們六一快樂;
vue-cli生成的template還須要配置axios,vuex,element等插件,該項目中將這些經常使用插件進行了配置;
項目開發中template能夠快速複用,也是能夠快速上手vue的一個demo;
技術棧:vue+vue-router+webpack+axios+echarts+ueditor+element UI+map+node-sass;
功能模塊:數據可視化,地圖,普通表格的增刪,可編輯表格,合併表格,左側菜單可展收;
適配:使用百分比佈局,適配pc全部機型;
目的:項目開發能夠快速複用的項目模板;javascript
1.props+$emit:父子組件傳值;
2.axios:
axios.interceptors.request(response)實現axios的全局攔截
axios.get(post)請求接口
3.vuex:實現公共數據模塊化管理和非父子組件通信
4.vuex-persistedstate:實現vuex數據的緩存
5.echarts:折線圖,柱狀圖,扇形圖和儀表等數據可視化
6.高德地圖:地圖展現
7.ueditor:富文本編輯器
8.utiles:裏面封裝了經常使用工具類
9.element UI+slot:可編輯表格
10.table:原生table實現表格拆分,展現複雜數據html
戳這裏
這個template後期會持續更新完善,歡迎star,謝謝噠vue
1.入口index.jsjava
import Vue from 'vue' import Vuex from 'vuex' import createPersistedState from 'vuex-persistedstate'//能夠將vuex數據緩存到sessionStorage中 import comTable from './modules/comTable' Vue.use(Vuex) export default new Vuex.Store({ modules: { comTable//將vuex拆分紅模塊 }, plugins: [createPersistedState({ storage: window.sessionStorage })] })
2.modules下面comTable.js文件:node
import * as comTableApi from '@/api/comTable'//將請求接口文件拆分 // initial state const state = { tableData: [], } // getters const getters = { allTableData: state => state.tableData, } // actions,異步提交,將ajax相關代碼寫入這個屬性,然後commit改變mutation const actions = { getAllData ({ commit }) { comTableApi.getComAjax('static/comTable.json',{obj1:'',obj2:''},(tableData) => { commit('setTableData', tableData) }) } } // mutations,同步提交,能夠改變state的值 const mutations = { setTableData (state,tableData) { state.tableData = tableData } }
3.在.vue中的使用
兩種方法:
this.$store.comTable.state(distapch)能夠設置
藉助mapGetters,mapActions輔助函數:webpack
import { mapGetters, mapActions } from "vuex"; computed: mapGetters({ tableData: "allTableData", }), mounted() { this.getAllData(); }, methods:{ ...mapActions([ 'getAllData'//須要調用 ]),}
echarts官網提供了setOption的參數,只須要獲取頁面的dom,而後設置setOption屬性ios
let histogram = this.$echarts.init(document.getElementById("histogram"));//tempalte設置一個標籤 // 繪製圖表 histogram.setOption({//對象參數爲obj title: { text: "ECharts 入門示例" }, tooltip: {}, xAxis: { data: ["襯衫", "羊毛衫", "雪紡衫", "褲子", "高跟鞋", "襪子"]//橫向座標值 }, yAxis: {}, series: [ { name: "銷量", type: "bar", data: [5, 20, 36, 10, 10, 20] } ] });
將下載好的static放到static目錄下,在main.js引入,在對應的vue文件中git
this.editor = UE.getEditor('editor', this.config); // 初始化UE this.editor.addListener("ready", function () { _this.editor.setContent(_this.defaultMsg); // 確保UE加載完成後,放入內容。 }); this.editor.getContent()//獲取富文本內容
我是使用高德地圖,在index.html全局導入github
<script src="http://webapi.amap.com/maps?v=1.4.6&key=9f63e48dcb3ccddc5cf6601788186f13&plugin=AMap.MouseTool"></script>//key爲我申請的,也能夠本身去申請
高德地圖官網案例web