1

在vue.config.js中配置

module.exports = {
    devServer: {
        proxy: {
            '/api': {
                target: 'http://localhost:3000',
                changeOrigin: true,
                pathRewrite: {
                    '/api': ''
                }
            }
        }
    
    },

}

修改完这个文件记得重启你的项目
在使用的时候(这里使用axios举例):
比如要访问的是 http://localhost:3000/interface1 这个接口

this.$axios.get('/api/interface1').then(res->{
    console.log(res);
})

希尔伯特_让_Z
15 声望0 粉丝

地表最强