【问题标题】:VueJs not sending data via Inertia to Laravel?VueJs 不通过 Inertia 向 Laravel 发送数据?
【发布时间】:2022-10-25 22:58:47
【问题描述】:

我有疑问,当我尝试通过 Inertia 发送一些数据时,由于某种原因,我在 Laravel 中没有收到任何建议?它可以与对象是代理对象这一事实有关吗? 以下是一些图片:

dd() in php controlelr

console.log() of the object before beeing sent via Inertia

Code of how I send the data + the console log right before sending it

更新:

这就是我将页面对象添加到页面数组的方式:

this.Pages.push({
            "name": "Untitled",
            "icon": "home",
            "order": order,
            "sections": [],
            "DisplayName":true,
            "Banner":"Medium",
            "Published":"Published",
            "DisplayLogo":true,
            "media":{
                'BackgroundImage': null,
                'LogoImage': null,
                'BackgroundImageHeight': null,
                'LogoImageHeight': null,
                'BackgroundImageStyle': {
                    "value": []
                },
                "LogoImageStyle": {
                    "value": []
                },
            }
        });

这是我的惯性形式:

        saveForm: {           
            applications: [],
        },

这是整个 save() 方法:

 Save() {
        if(this.localProduct.translation.applications.mobile_label[this.currentMobileLabel] != undefined){
            if(this.localProduct.translation.applications.mobile_label[this.currentMobileLabel].data == undefined){
                this.localProduct.translation.applications.mobile_label[this.currentMobileLabel] = {
                    "Pages": this.Pages,
                    "media": this.media,
                    "name": this.localProduct.translation.applications.mobile_label[this.currentMobileLabel].name,
                    "active": this.localProduct.translation.applications.mobile_label[this.currentMobileLabel].active,
                };
            }
            else{
                this.localProduct.translation.applications.mobile_label[this.currentMobileLabel] = {
                    "Pages": this.Pages,
                    "media": this.media,
                    "name": this.localProduct.translation.applications.mobile_label[this.currentMobileLabel].name,
                    "active": this.localProduct.translation.applications.mobile_label[this.currentMobileLabel].active,
                    "data" : this.localProduct.translation.applications.mobile_label[this.currentMobileLabel].data,
                };
            }
        }    
        this.saveForm.applications = toRaw(this.localProduct.translation.applications);
        
        console.log(this.saveForm);

        Inertia.post(this.route(`product.translations.applications`,{translation: this.localProduct.translation.id}),this.saveForm);
    },

应用程序应该是数组,mobile_label 也应该是数组。原样。

!!!也很重要!!! 在项目开始转向 vue js 3 之前,所有这些代码都有效,我想许多库必须为其他库更新/交换。

【问题讨论】:

  • 请不要使用图片链接。图片链接最终可能会中断,而且一些答案可能需要包含您的一些代码,并且没有人喜欢从图片中转录代码......

标签: laravel vue.js vuejs3 inertiajs


【解决方案1】:

根据Inertia's documentation,使用Inertia.post() 时预期的第一个参数是一个URL。所有this.route(`product.translations.applications`,{translation: thislocalProduct.translation.id}) 都返回一个URL 吗?

【讨论】:

  • 是的,否则我将无法接收在指向具有 dd() 的特定控制器的特定端点中发生的 dd()。
  • 好的。您需要发布更多代码(请不要作为屏幕截图)。你的 console.log 说 applications 是 Array(0) 但它有一个名为 mobile_label 的对象属性,所以 applications 是一个数组还是对象?奇怪的是两者兼而有之。将需要查看更多您的<script> 代码。你是如何创建这些对象和数组的,你是如何让它们反应的,你是如何修改它们的,等等。
  • 所以应用程序应该是对象数组。我将在原始帖子中添加一些额外的代码。
【解决方案2】:

对于遇到同样问题的任何人,请检查分配给变量的数组/对象,可能会出现像我这样的错误,我用这个修复了我的错误:

        this.saveForm.applications = toRaw(this.localProduct.translation.applications);
        var fixed = Object.assign({},this.localProduct.translation.applications);
        Inertia.post(this.route(`product.translations.applications`,{translation: this.localProduct.translation.id}),fixed);

【讨论】:

    【解决方案3】:

    谢谢。请展示您如何管理控制器中的数据?

    【讨论】:

    猜你喜欢
    • 2021-06-25
    • 1970-01-01
    • 2019-02-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-25
    • 1970-01-01
    • 2017-02-24
    • 1970-01-01
    相关资源
    最近更新 更多