## 示例axios配置 以下是本演示项目中`main.js`的片段截取 ```js import axios from 'axios'; const request = axios.create({ baseURL: 'http://localhost', timeout: 1000 * 60, withCredentials: true, }); // respone 拦截器 request.interceptors.response.use( response => { const { data = {}, config } = response; const { code = 0 } = data; if (config && config.interceptors === false) { // 请求配置不做返回拦截的情况 return response; } else { if (`${code}` === '0' || `${code}` === '200') { // 请求成功 return data; } else { // 其它错误,开发环境提示 return { code }; } } }, error => { return { code: 404 }; }); Vue.prototype.$axios = request; ``` ## Scheme默认逻辑 * 查询列表 传入$http时,如果没有配置searchAPI,则按照以下规则处理: **默认路径** `option.searchMethod` 或者默认为 `/page` **处理规则** ```js (response) => { const { result = {} } = response || {}; const { list = [] } = result || {}; this.tableData = list; this.totalCount = result[totalCountAlias] || 0; } ``` * 查询数据 传入$http时,如果没有配置getAPI,则按照以下规则处理: **默认路径** `option.getMethod/${id}` 或者默认为 `/id/${id}` **处理规则** ```js (response) => { const { result = {} } = response || {}; this.setFormModel(result); } ``` * 查询详情 传入$http时,如果没有配置detailAPI,则按照以下规则处理: **默认路径** `option.detailMethod/${id}` 或者默认为 `/info/${id}` **处理规则** ```js (response) => { const { result = {} } = response || {}; this.setFormModel(result); } ``` * 新增保存 传入$http时,如果没有配置newMethod,则按照以下规则处理: **默认路径** `option.newMethod` 或者默认为 `/add` **处理规则** ```js (response) => { const { code } = response || {}; if (`${code}` === '0') { // ... } } ``` * 编辑保存 传入$http时,如果没有配置editMethod,则按照以下规则处理: **默认路径** `option.editMethod` 或者默认为 `/update` **处理规则** ```js (response) => { const { code } = response || {}; if (`${code}` === '0') { // ... } } ``` * 删除/批量删除 传入$http时,如果没有配置deleteMethod,则按照以下规则处理: **默认路径** `option.deleteMethod` 或者默认为 `/delete` **处理规则** ```js (response) => { const { code } = response || {}; if (`${code}` === '0') { // ... } } ``` ## Scheme自定义API 使用方法见[示例](/component/scheme#zi-ding-yiapi-pei-zhi) * searchAPI 查询列表 ```js (param) => { // param 包含分页的搜索条件 return { result, totalCount }; // result 数据源 Object类型; totalCount 总数 Number类型 } ``` * detailAPI 查询详情 ```js (param) => { // param 当前行数据 return result; // result 查询结果 Object类型 } ``` * getAPI 编辑查询数据 ```js (param) => { // param 当前行数据 return result; // result 查询结果 Object类型 } ``` * deleteAPI 删除 ```js (selection) => { // selection 选中的数据 return result; // result 是否执行成功 Boolean类型 } ``` * newAPI 新增保存 ```js (model) => { // model 表单数据 return result; // result 是否执行成功 Boolean类型 } ``` * editAPI 编辑保存 ```js (model) => { // model 表单数据 return result; // result 是否执行成功 Boolean类型 } ```