mock
安装mockjs
npm i mockjs --save
写mock接口数据
import Mock from 'mockjs'
// 引入 json数据
import analysis from './analysis.json'
Mock.mock('/mock/analysis', {
code:200,
data: analysis
})
//mock请求封装
安装axios
import axios from 'axios'
export const request = (options) => {
return new Promise((resolve, reject) => {
const service = axios.create({
baseURL: '/mock',
timeout: 2000, // request timeout
})
service.interceptors.request.use((config) => {
return config
})
service.interceptors.response.use(
(response) => {
return response.data
},
(error) => {
return Promise.reject(error)
},
)
// 请求处理
service(options)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}
export default request
//请求接口封装
import mocks from '../util/mock'
export const Analysis=()=> mocks('/analysis','get')