【问题标题】:How to deploy Vue.js 2 app and Laravel 5.4 API on the same hosting如何在同一主机上部署 Vue.js 2 应用程序和 Laravel 5.4 API
【发布时间】:2018-07-28 00:24:39
【问题描述】:

我使用 Laravel 5.4 编写了一个 API,并使用 Vue.js 2 从我的前端连接到它。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;
});

解决方法是什么?

【问题讨论】:

    标签: javascript laravel rest api vue.js


    【解决方案1】:

    假设您的网络服务器正在侦听端口 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/',
    });
    

    【讨论】:

    • 谢谢你)我会检查一下,然后给你我的回复。
    猜你喜欢
    • 2018-08-17
    • 1970-01-01
    • 2020-05-15
    • 2022-07-06
    • 1970-01-01
    • 2018-12-02
    • 2019-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多