路径相关 请问老师这个路径指的是什么路径
来源:3-2 axios 封装 & 数据获取

慕仰9344612
2019-09-05
请问老师这个路径指的是什么路径
vue.config文档里面的 get(’/api/seller’
这个路径是data.json 里面的路径还是api那个文件夹的路径
devServer: {
before(app) {
app.get(’/api/seller’, function (req, res) {
res.json({
errno: 0,
data: seller
写回答
3回答
-
慕仰9344612
提问者
2019-09-05
老师 我还有个问题
那个
prod.serve.js文件里面的配置是给production 用的吗
我复制那个配置进vue.config.js不管用
012019-09-05 -
慕仰9344612
提问者
2019-09-05
//写成这样终于成功了 ,感觉应该是新版本的原因,直接给以通过‘/api/seller’赋予这个接口 //这个地址,之前因为那个api文件夹的原因一直想错了 const appData = require('./data.json') const seller = appData.seller const goods = appData.goods const ratings = appData.ratings module.exports = { 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 }) }) } }, }
00 -
ustbhuangyi
2019-09-05
app.get('/api/seller', function (req, res) {
res.json({
errno: 0,
data: seller
})
})
其中 app.get 表示处理 get 请求, `/api/seller` 表示对于这个路由(也就是请求 url),我们会走到后面的 function,这里的 seller ,是读取的 mock 数据
const appData = require('./data.json')
const seller = appData.seller
data.json 是 mock 数据,这些都是后端,与前端 api 目录无关,后端只要定义好这些接口路由,前端发送请求就能通过这个路由请求到数据了。00
相似问题
路径问题
回答 1