赞
踩
<script src="//unpkg.com/vue@2/dist/vue.js"></script> <script src="//unpkg.com/element-ui@2.15.13/lib/index.js"></script> <div id="app"> <template> <el-table :data="tableData" border style="width: 100%"> <el-table-column fixed type="index" label="序号" width="50"> </el-table-column> <el-table-column fixed prop="date" label="日期" width="150"> </el-table-column> <el-table-column prop="name" label="姓名" width="120"> </el-table-column> <el-table-column prop="province" label="省份" width="120"> </el-table-column> <el-table-column prop="city" label="市区" width="120"> </el-table-column> <el-table-column prop="address" label="地址" width="300"> </el-table-column> <el-table-column prop="zip" label="邮编" width="120"> </el-table-column> <el-table-column label="操作" width="170"> <template slot-scope="scope"> <el-button @click="moveTop(scope.row, scope.$index)" type="text" size="small">置顶</el-button> <el-button @click="moveUp(scope.row, scope.$index)" type="text" size="small">上移</el-button> <el-button @click="moveDown(scope.row, scope.$index)" type="text" size="small">下移</el-button> </template> </el-table-column> </el-table> </template> </div>
var Main = { methods: { moveTop(row, idx){ this.tableData.splice(idx, 1) this.tableData.unshift(row) }, moveUp(row, idx){ this.tableData[idx] = this.tableData.splice(idx - 1, 1, row)[0] }, moveDown(row, idx){ this.tableData[idx] = this.tableData.splice(idx + 1, 1, row)[0] }, }, data() { return { tableData: [{ date: '2016-05-04', name: '王小虎', province: '上海', city: '普陀区', address: '上海市普陀区金沙江路 1517 弄', zip: 200333 }, { date: '2016-05-02', name: '王小虎', province: '上海', city: '普陀区', address: '上海市普陀区金沙江路 1518 弄', zip: 200333 }, { date: '2016-05-01', name: '王小虎', province: '上海', city: '普陀区', address: '上海市普陀区金沙江路 1519 弄', zip: 200333 }, { date: '2016-05-03', name: '王小虎', province: '上海', city: '普陀区', address: '上海市普陀区金沙江路 1516 弄', zip: 200333 }] } } } var Ctor = Vue.extend(Main) new Ctor().$mount('#app')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。