客户端 Custom (web端)
vue.config.js
module.exports = {
...,
devServer: {
...,
proxy: {
'/api': {
target: 'http://localhost:8888',
changeOrigin: true,
pathRewrite: {
'^/api': '/'
}
}
}
}
}
Component Vue
import Axios from 'axios'
export default {
...,
methods: {
...,
TestGetServer: {
Axios.get('/api').then(res => {
console.log(res.data)
})
}
}
}
服务端 Server (node端)
index.js / main.js
const express = require('express')
const app = express()
app.get('/', (req, res) => {
res.send('Welcome to node server!')
})
console.log('server project is open: http://localhost:8888 ')
app.listen(8888)