diff --git a/src/components/G2/G2.js b/src/components/G2/G2.js index 68f1f27a..0d1becd5 100644 --- a/src/components/G2/G2.js +++ b/src/components/G2/G2.js @@ -41,7 +41,6 @@ export default { watch: { // 数据改变 data () { - console.log('111') this.changeData() } }, diff --git a/src/mock/chart/G2Line.js b/src/mock/chart/G2Line.js new file mode 100644 index 00000000..7f081832 --- /dev/null +++ b/src/mock/chart/G2Line.js @@ -0,0 +1,25 @@ +import Mock from 'mockjs' + +Mock.mock('/api/chart/G2Line', 'post', ({body, type, url}) => { + const _body = JSON.parse(body) + switch (_body.code) { + case 1: + return { + code: 0, + msg: '请求成功', + data: [ + { year: '1991', value: 3 }, + { year: '1992', value: 4 }, + { year: '1993', value: 3.5 }, + { year: '1994', value: 5 }, + { year: '1995', value: 4.9 }, + { year: '1996', value: 6 }, + { year: '1997', value: 7 }, + { year: '1998', value: 9 }, + { year: '1999', value: 13 } + ] + } + default: + return {} + } +}) diff --git a/src/mock/chart/G2Line1.js b/src/mock/chart/G2Line1.js deleted file mode 100644 index 6948d69d..00000000 --- a/src/mock/chart/G2Line1.js +++ /dev/null @@ -1,19 +0,0 @@ -import Mock from 'mockjs' - -Mock.mock('/api/chart/G2Line1', () => { - return { - code: 0, - msg: '请求成功', - data: [ - { year: '1991', value: 3 }, - { year: '1992', value: 4 }, - { year: '1993', value: 3.5 }, - { year: '1994', value: 5 }, - { year: '1995', value: 4.9 }, - { year: '1996', value: 6 }, - { year: '1997', value: 7 }, - { year: '1998', value: 9 }, - { year: '1999', value: 13 } - ] - } -}) diff --git a/src/mock/chart/index.js b/src/mock/chart/index.js new file mode 100644 index 00000000..24f0d417 --- /dev/null +++ b/src/mock/chart/index.js @@ -0,0 +1 @@ +import './G2Line' diff --git a/src/mock/demo/index.js b/src/mock/demo/index.js new file mode 100644 index 00000000..b48ff9ea --- /dev/null +++ b/src/mock/demo/index.js @@ -0,0 +1 @@ +import './001' diff --git a/src/mock/index.js b/src/mock/index.js index f997f5be..f6694223 100644 --- a/src/mock/index.js +++ b/src/mock/index.js @@ -1,5 +1,12 @@ -import '@/mock/demo/001' +import Mock from 'mockjs' + +import '@/mock/demo' import '@/mock/login' -import '@/mock/chart/G2Line1' +import '@/mock/chart' + +// 设置全局延时 没有延时的话有时候会检测不到数据变化 建议保留 +Mock.setup({ + timeout: '600-1000' +}) diff --git a/src/pages/demo/chart/index/index.vue b/src/pages/demo/chart/index/index.vue index af93324b..5ef64d1f 100644 --- a/src/pages/demo/chart/index/index.vue +++ b/src/pages/demo/chart/index/index.vue @@ -34,17 +34,19 @@ export default { } }, mounted () { - setTimeout(() => { + this.syncData() + }, + methods: { + // 请求图表数据 + syncData () { const api = [ - '/api/chart/G2Line1' + {url: '/api/chart/G2Line', data: {code: 1}} ] - this.$axios.all(api.map(e => this.$axios.get(e))) + this.$axios.all(api.map(e => this.$axios.post(e.url, e.data))) .then(this.$axios.spread((G2Line1) => { this.G2Line1 = G2Line1 })) - }, 300) - }, - methods: { + }, // 改变尺寸 resizeHandler (name) { this.$nextTick(() => {