talk is cheap, show me the code.
- import axios from 'axios'
- export default class LoadData {
- constructor(method, url, params) {
- this.config = { method, url }
- if (method === 'get') this.config.params = { ...params }
- if (method === 'post') this.config.data = { ...params }
- }
- getData() {
- return new Promise(resolve => {
- axios(this.config).then(res => {
- resolve(res.data)
- })
- })
- }
- }
- // 获取后端的数据
- loadData() {
- let params = {
- // projectId: this.projectId
- projectId: 145,
- // fuzzy: '',
- }
- let load = new LoadData(
- 'get',
- API.whole_stationPlan_externalPro,
- params
- )
- load.getData().then(json => {
- console.log(json.obj)
- this.spreadDataSource = [...json.obj]
- })
- },
复制代码 |