簡體   English   中英

Inertia.JS ,如果沒有驗證錯誤,Laravel 關閉模式

[英]Inertia.JS , Laravel closing modal if no validation errors

所以我有以下方法:

methods: {
    submit() {    
      this.$inertia.post('/projects', this.form);
      this.openModal = false;
      
    },
},

但即使存在驗證錯誤,它也會關閉我的模式。 我也試過

this.$inertia.post('/projects', this.form);
      if(!this.$page.props.errors) {
              this.openModal = false;
}

如果有驗證錯誤,它不會關閉模態,但如果沒有驗證錯誤,它不會關閉它。

this.$inertia.post是異步執行的,因此this.openModal = false很可能會在您從服務器獲得響應之前完成。 如果你想明白我的意思,輸入sleep(10); /projects路由的控制器中的某處 - 在 Inertia 從服務器返回響應之前,將執行this.$inertia.post之后的任何代碼。

我假設您的控制器重定向回來。 如果您的模態在頁面加載時默認關閉,那么您可以在出現以下錯誤時保持模態打開:

this.$inertia.post(
    this.route("/projects"),
    this.form,
    {
        preserveState: (page) => Object.keys(page.props.errors).length > 0,
    }
);

請參閱Inertia 文檔中的組件狀態部分以供參考。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM