0

用mock方法对json文件生成随机数组在vue中无法获取数据

这是mockServer.js文件

/*
使用mockjs提供mock数据接口
*/

import Mock from 'mockjs'
import data from './data.json'

//返回goods接口
Mock.mock('/goods',{code:0,data:data.goods})
//返回ratings的接口
Mock.mock('/ratings',{code:0,data:data.ratings})
//返回ginfo的接口
Mock.mock('/info',{code:0,data:data.info})

//不需要向外暴露


### 这个mutations.js 代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)

import {
    RESEIVE_ADDRESS,
    RESEIVE_FOODSTYPES,
    RESEIVE_SHOPS,
    RESEIVE_INFO,
    RESEIVE_RATINGS,
    RESEIVE_GOODS
} from './mutation-types.js'
export default {
   [RESEIVE_ADDRESS](state,{address}){
       state.address = address
   },
    [RESEIVE_FOODSTYPES](state,{foodstypes}){
        state.foodstypes = foodstypes
    },
    [RESEIVE_SHOPS](state,{shops}){
        state.shops = shops
    },

    [RESEIVE_INFO](state,{info}){
        state.info = info
    },
    [RESEIVE_RATINGS](state,{ratings}){
        state.ratings = ratings
    },
    [RESEIVE_GOODS](state,{goods}){
        state.goods = goods
    }
}

这个目录文件,data.json和mockServer.js放在mock文件中,但是还是报错:

clipboard.png

clipboard.png

这个是路径问题吗,还是配置问题?盖怎么解决呢?

Leon 3
7月14日提问
0 个回答

撰写答案

推广链接