1)跑一个服务做后台
1.1)使用node.js的express框架
1.2)服务地址:http://localhost:3000/ttt
2)跑一个服务做前台
2.1)使用vue的axios请求数据
2.2)服务地址:http://localhost:8080/#/
2.3)前端设置跨域代理
后台代码:
var express = require('express')
var app = express()
app.get('/ttt', (req, res) => {
res.send({ hello: "get" })
})
app.post('/ttt', (req, res) => {
res.send({ hello: "post" })
})
app.listen(3000, () => {
console.log('Example app listening on port 3000!');
})
前台代码post:
getData () {
axios.post('/ttt')
.then((res) => {
console.log(res)
})
}
获得:
前台代码get:
getData () {
axios.get('/ttt')
.then((res) => {
console.log(res)
})
}
获得: