javascript - vue-clin project, dist folder after npm run build, index.html cannot obtain its own data through json, mock
高洛峰
高洛峰 2017-05-16 13:29:06
0
2
794

The project npm run dev and post-build tests are all fine. Now when I open the post-build dist folder index.html, the following error appears

Is it because the data and content my project relies on are all mocked through json files. After the build, the json data is not packaged into the dist folder, so the data cannot be requested? How to deal with it

Project directory,

Mock data in build/dev-server.js

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

var apiRouters = express.Router();
apiRouters.get('/seller',function(req,res){
  res.json({
    errno:0,
    data:seller
  })
})

apiRouters.get('/goods',function(req,res){
  res.json({
    errno:0,
    data:goods
  })
})

apiRouters.get('/ratings',function(req,res){
  res.json({
    errno:0,
    data:ratings
  })
})


app.use('/api',apiRouters)
//数据mock

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
迷茫

The api you use should use a relative path, so you need to open the http service and start the project after dist. You may use ./ or /, and then open the file directly, and the path will be read as the path of your computer's hard disk.

仅有的幸福

The error message is cross-domain

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!