赞
踩
1.js发出请求
mounted() { this.$store.dispatch('showHeader'); this.loadData(); }, methods: { loadData() { var params = { page: this.currentPage, pageSize: this.pageSize, name: this.formInline.name, address: this.formInline.address }; getUserList(params).then(function(result){ this.tableData = result.data.list; this.total = result.data.total; this.loading2 = false; }.bind(this)).catch(function (error) { this.loading2 = false; console.log(error); }.bind(this)); } } 跳转 export const getUserList = params => { return Axios.get(`${BASE_PATH}/user/list`, { params: params }).then(res => res.data); };
2.后台服务
@RestController @RequestMapping("/user") public class UserController { @GetMapping("/list") public ResponseData queryUsers(String name, String address, Integer page, Integer pageSize){ if (page == null) { page = 1; } if (pageSize == null) { pageSize = 10; } List<UserVo> users = new ArrayList<UserVo>(); if (page == 1) { for (int i = 1; i < 11; i++) { users.add(new UserVo(i, "王小虎" + i, "上海市普陀区金沙江路 1518 弄", "2016-05-02")); } } if (page == 2) { for (int i = 11; i < 20; i++) { users.add(new UserVo(i, "王小虎" + i, "上海市普陀区金沙江路 1518 弄", "2016-05-02")); } } if (!address.equals("")) { users = new ArrayList<UserVo>(); users.add(new UserVo(111, "王小虎111", "上海市普陀区金沙江路 1518 弄", "2016-05-02")); } Map<String, Object> result = new HashMap (); result.put("list", users); result.put("currentPage", page); result.put("total", 19); result.put("pageSize", pageSize); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ResponseData.ok(result); }
3.返回数据显示js
export default { data() { return { tableData: [], formInline: { name: '', address: '', id:'' }, currentPage:1, total:0, pageSize:10, addressList:["上海市普陀区金沙江路 1518 弄", "上海市普陀区金沙江路 1519 弄", "上海市普陀区金沙江路 1517 弄"], pickerOptions0: { disabledDate(time) { return time.getTime() < Date.now() - 8.64e7; } }, selectDate:'', dialogFormVisible: false, formLabelWidth: '120px', form: { name: '', address: '', id:'' }, loading2: false, options: [{ value: '湖南', label: '湖南', children: [{ value: '长沙', label: '长沙' }, { value: '株洲', label: '株洲' }, { value: '湘潭', label: '湘潭' }] }], selectedOptions: [], multipleSelection: [] } }, ```methods: { getUserList(params).then(function(result){ //赋值 this.tableData = result.data.list; this.total = result.data.total; this.loading2 = false; }.bind(this)).catch(function (error) { this.loading2 = false; console.log(error); }.bind(this)); }
4控件绑定数据
<el-form-item label="城市"> <el-cascader :options="options" v-model="selectedOptions"></el-cascader> </el-form-item> <el-form-item label="姓名"> <el-input v-model="formInline.name" placeholder="姓名"></el-input> </el-form-item> <el-form-item label="地址"> <el-select v-model="formInline.address" placeholder="地址"> <el-option v-for="item in addressList" :key="item" :label="item" :value="item"></el-option> </el-select> </el-form-item> <el-form-item> <el-date-picker v-model="selectDate" type="date" placeholder="选择日期" :picker-options="pickerOptions0"> </el-date-picker> </el-form-item> <el-form-item> <el-button type="primary" @click="onSubmit">查询</el-button> </el-form-item> </el-form> //绑定tableData <el-table :data="tableData" style="width: 100%" v-loading="loading2" element-loading-text="拼命加载中" @selection-change="handleSelectionChange"> <el-table-column type="selection" width="55"></el-table-column> <el-table-column prop="name" label="姓名" width="180"></el-table-column> <el-table-column prop="address" label="地址"></el-table-column> <el-table-column prop="date" label="日期" width="180"></el-table-column> <el-table-column fixed="right" label="操作" width="140"> <template scope="scope"> <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button> <el-button type="text" size="small" @click="showEditDialog(scope.$index)">编辑</el-button> <el-button type="text" size="small" @click="removeData(scope.$index)">删除</el-button> </template> </el-table-column> </el-table> <div class="block"> <div class="r_btn"> <el-button type="primary" @click="batchRemove">批量删除</el-button> </div> <div class="r_page"> <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination> </div> </div> <!-- Form --> <el-dialog title="编辑信息" :visible.sync="dialogFormVisible"> <el-form :model="form"> <el-form-item label="姓名" :label-width="formLabelWidth"> <el-input v-model="form.name" auto-complete="off"></el-input> </el-form-item> <el-form-item label="地址" :label-width="formLabelWidth"> <el-input v-model="form.address" auto-complete="off"></el-input> </el-form-item> </el-form> <div slot="footer" class="dialog-footer"> <el-button @click="dialogFormVisible = false">取 消</el-button> <el-button type="primary" @click="update">确 定</el-button> </div> </el-dialog>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。