http://localhost:8080/api/seller 404 (Not Found)
来源:16-2 Vue-resource应用(下)

慕斯8533714
2017-11-21
VUE2.0
webpack.dev.conf.js配置
const express = require('express');
const app = express();
var appData = require('../data.json');
var seller = appData.seller;
var goods = appData.goods;
var ratings = appData.ratings;
var apiRoutes = express.Router();
apiRoutes.get('/seller',function (req,res) {
res.json({
errno:0,
data: seller
});
});
apiRoutes.get('/goods',function (req,res) {
res.json({
errno:0,
data: goods
});
});
apiRoutes.get('/ratings',function (req,res) {
res.json({
errno:0,
data: ratings
});
});
app.use('/api',apiRoutes);
main.js 配置
Vue.config.productionTip = false;
Vue.use(VueRouter);
Vue.use(VueResource);
const routes = [
{path: '/', redirect: '/goods'},
{path: '/goods', component: goods},
{path: '/seller', component: sellers},
{path: '/rating', component: ratings}
];
var router = new VueRouter({routes, linkActiveClass: 'active'});
new Vue({
router,
render: h => h(App)
}).$mount('#app');
重启服务之后,还是报错404,请老师同学帮忙看一下,谢谢
2回答
-
LittleWorker
2017-12-25
如果是vue 2.0的话,参考老师写的更新说明https://github.com/ustbhuangyi/vue-sell/blob/master/update.md
你的问题应该是webpack.dev.conf.js中需要添加
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
2017-11-21
你是不是用新版的脚手架初始化的项目?
022017-11-22
相似问题