Mock数据

在文件【vue.config.js】 - devServer 字段 - before(app)函数配置数据接口访问

seller【2】Mock数据(接口访问配置)

seller【2】Mock数据(接口访问配置)

const appData = require('./data.json')
const seller = appData.seller
const goods = appData.goods
const ratings = appData.ratings


devServer: {
        before(app) {
            app.get('/api/seller', function(req, res) {
                res.json({
                    errno: 0,
                    data: seller
                })
            })
            app.get('/api/goods', function(req, res) {
                res.json({
                    errno: 0,
                    data: goods
                })
            })
            app.get('/api/ratings', function(req, res) {
                res.json({
                    errno: 0,
                    data: ratings
                })
            })
        }
    }

运行项目:npm run serve

http://localhost:8081/api/goods 即可访问到data.json数据

seller【2】Mock数据(接口访问配置)

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2021-11-27
  • 2021-11-08
  • 2022-12-23
  • 2021-11-19
猜你喜欢
  • 2021-12-18
  • 2022-12-23
  • 2022-01-28
  • 2021-12-24
  • 2021-05-20
  • 2022-12-23
  • 2021-10-13
相关资源
相似解决方案