vue-manage-system-master中Prop應用
阿新 • • 發佈:2018-12-04
vue-manage-system-master
渲染頁面:
<template> <div class="table"> <div class="crumbs"> <el-breadcrumb separator="/"> <el-breadcrumb-item><i class="el-icon-menu"></i> 表格</el-breadcrumb-item> <el-breadcrumb-item>基礎表格</el-breadcrumb-item> </el-breadcrumb> </div> <div class="handle-box"> <el-button type="primary" icon="delete" class="handle-del mr10" @click="delAll">批量刪除</el-button> <el-select v-model="select_cate" placeholder="篩選醫院" class="handle-select mr10"> <!--迴圈--> <el-option key="1" label="廣東省" value="廣東省"></el-option> <el-option key="2" label="湖南省" value="湖南省"></el-option> </el-select> <el-input v-model="select_word" placeholder="篩選關鍵詞" class="handle-input mr10"></el-input> <el-button type="primary" icon="search" @click="search">搜尋</el-button> </div> <!---this.tableData的格式必須是陣列套物件,prop中值為物件的鍵
--> <el-table border :data='this.tableData' style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange"> <el-table-column type="selection" width="55"></el-table-column> <el-table-column prop="name" label = "姓名" sortable width="150"> </el-table-column> <el-table-column prop="doc_job" label="職位" width="120"> </el-table-column> <el-table-column prop="doc_hos" label="醫院" > </el-table-column> <el-table-column prop="doc_tel" label="聯絡方式" > </el-table-column> <el-table-column label="操作" width="180"> <template slot-scope="scope"> <el-button size="small" @click="handleEdit(scope.$index, scope.row)">編輯</el-button> <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">刪除</el-button> </template> </el-table-column> </el-table> <div class="pagination"> <el-pagination @current-change ="handleCurrentChange" layout="prev, pager, next" :total="1"> </el-pagination> </div> </div> </template> <script> export default { data() { return { url: './static/vuetable.json', tableData: [], cur_page: 1, multipleSelection: [], select_cate: '', select_word: '', del_list: [], is_search: false } }, created(){ this.getData(); }, methods: { handleCurrentChange(val){ this.cur_page = val; this.getData(); }, getData(){ let self = this; // 通過NODE_ENV可以來設定環境變數(預設值為development)。 在terminal裡面執行下面的命令就會有開發環境的除錯資料,例如日誌、mongodb的資料操作等等。一般我們通過檢查這個值來分別對開發環境和生產環境下做不同的處理。可以在命令列中通過下面的方式設定這個值: //linux & mac: export NODE_ENV=production windows:set NODE_ENV=production if(process.env.NODE_ENV === 'development'){ //獲取後臺的資料路徑self.url = 'http://www.baidu.com'; }; let params = new URLSearchParams();//使用axios傳參的轉換物件 params.append('page', self.cur_page);//新增引數 self.$axios.post(self.url,params).then((res) => { self.tableData = res.data; }) }, search(){ //關鍵字查詢; this.is_search = true; }, handleEdit(index, row) { this.$message('編輯第'+(index+1)+'行'); }, handleDelete(index, row) { this.$message.error('刪除第'+(index+1)+'行'); }, delAll(){ const self = this, length = self.multipleSelection.length; let str = ''; self.del_list = self.del_list.concat(self.multipleSelection); for (let i = 0; i < length; i++) { str += self.multipleSelection[i].name + ' '; } self.$message.error('刪除了'+str); self.multipleSelection = []; }, //獲取偵聽選中的物件 handleSelectionChange(val) { this.multipleSelection = val; } } } </script> <style scoped> .handle-box{ margin-bottom: 20px; } .handle-select{ width: 120px; } .handle-input{ width: 300px; display: inline-block; } </style>