繁体   English   中英

如何在同一主机上部署Vue.js 2应用程序和Laravel 5.4 API

[英]How to deploy Vue.js 2 app and Laravel 5.4 API on the same hosting

我已经使用Laravel 5.4编写了一个API,并使用Vue.js 2从前端将其连接到该API。该API在http://localhost:8000/上运行,而Vue应用程序在http://localhost:8080/

我应该如何将它们部署在同一主机上? 我应该如何处理axios请求,例如:

axios.post(`http://localhost:8000/api/requests`, {
    'fname': this.fname,
    'lname': this.lname,
    'email': this.email,
    'phone': this.phone
})
.then(response => {
    if(response.data.success) {
        this.showSpinner = false;
        this.success = true;
        this.message = response.data.message;
    }
})  
.catch(error => {
    context.error = error;
});

解决方法是什么?

假设您的Web服务器正在侦听端口80,则只需在url中提供路径,例如:

axios.post(`/api/requests`, {
    'fname': this.fname,
    'lname': this.lname,
    'email': this.email,
    'phone': this.phone
})

您可以根据需要设置默认配置以设置基本URL和端口:

var instance = axios.create({
    baseURL: 'https://some-domain.com:8000/api/',
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM