Closed jasminecjc closed 7 years ago
model/funnel.js
import { query } from '../services/funnel'; export default { namespace: 'funnel', state: { funnelList: [], dimension: [], chart: [], details: [], loading: false, modalVisible: false, modalType: 'create' }, subscriptions: { setup({ dispatch, history }) { history.listen(location => { if(location.pathname === '/funnel') { dispatch({ type: 'query', payload: {} }) } }) } }, effects: { *query({ payload }, { select, call, put }) { yield put({ type: 'showLoading' }); const { data } = yield call(query); if (data) { yield put({ type: 'querySuccess', payload: { chart: data.chart, } }); } }, *create(){}, *addTo(){} }, reducers: { showLoading(state, action){ return { ...state, loading: true }; }, // 控制加载状态的 reducer showModal(){}, // 控制 Modal 显示状态的 reducer hideModal(){}, // 使用服务器数据返回 querySuccess(state, action) { return {...state, ...action.payload, loading: false}; }, createSuccess(){}, addToSucces(){}, } };
services/funnle.js
import request from '../utils/request'; import qs from 'qs'; export async function query(params) { return request(`/api/funnel?${qs.stringify(params)}`); }
mock/funnel.js
'use strict'; const mockjs = require('mockjs'); module.exports = { 'GET /api/funnel': function (req, res) { const a = [100, 80, 60, 40, 20].reverse(); const data = mockjs.mock({ chart: { data: ['曝光', '下载', '注册', '平台首次呼叫', '首单'].reverse(), seriesData: { stayData: a, lostData: a.map(item => 100 - item), } } }); res.json({ success: true, chart: data.chart }); }, };
报错:
request.js:25 GET http://localhost:8989/api/funnel? 404 (Not Found)
重启 npm start 试试,另外直接访问 http://localhost:8989/api/funnel 也是 404 ?
npm start
重启了,直接访问接口 ,控制台的报错是 proxy: proxy.config.js parse error: Error: Cannot find module 'mockjs',不知道为什么我没remove过什么npm modules,安装了mockjs之后解决了
proxy: proxy.config.js parse error: Error: Cannot find module 'mockjs'
model/funnel.js
services/funnle.js
mock/funnel.js
报错: