vue3.0加载本地json 以及跨域问题解决

2019-03-26  本文已影响0人  灯火楼台666
// 导入express
const express = require('express');

// 创建express实例
const app = express();

// 读取json数据
var goods = require('./data/goods.json');
var ratings = require('./data/ratings.json');
var seller = require('./data/seller.json');

module.exports = {
  // 根路径
  publicPath: '/',

  outputDir: 'dist',

  assetsDir: 'assets',

  lintOnSave: false,

  devServer: {
    open: false,
    // host: 'localhost',
    port: 8082,
    https: false,

    proxy:{
      'api':{
        target:'http//localhost:5000/api',
        ws:true,
        changOrigin:true,
        pathRewrite:{
          '^/api':''
        }
      }
    },

    before(app){

      app.get('/api/goods',(req,res) =>{
        res.json(goods)
      });

      app.get('/api/ratings',(req,res) =>{
        res.json(ratings)
      });

      app.get('/api/seller',(req,res) =>{
        res.json(seller)
      });
    }

  }

}
跨域问题参考
https://www.cnblogs.com/zhixi/p/9541162.html

https://www.cnblogs.com/zuoan-oopp/p/9101240.html
上一篇下一篇

猜你喜欢

热点阅读