代码之家  ›  专栏  ›  技术社区  ›  David

付款后重定向到另一个页面并显示成功消息-Vue.JS

  •  1
  • David  · 技术社区  · 9 年前

    我有一个付款模式,一旦用户填写,它就会打开,如果付款成功,我想重定向到另一个页面,并显示成功消息。我正在使用Laravel 5.3和Vue JS。

    现在,它看起来是这样的,我让它重定向到另一个页面,但我如何附加某种成功消息?

    this.$http.post('/cropkit/public/subscriptions', this.$data).then(
        window.location.replace('/cropkit/public/profile/dashboard'),
        response => this.status = response.body.status
    );
    

    /********编辑*********/

    以下是检查是否成功或发生错误的解决方案:

    swal 是一个警报消息插件

                        this.$http.post('/mysite/subscriptions', this.$data).then((response) => {
                            swal({
                               title: "Success!",
                               text: "Payment has been processed!",
                               type: "success",
                               showConfirmButton: false,
                               allowEscapeKey: false,
                               allowOutsideClick: false,
                               timer: 5000,
                            }),
                            setTimeout(function(){
                                window.location.replace('/mysite/profile/dashboard');
                            }, 4000)
                        }, (response) => {
                            this.status = response.body.status
                        });
    
    1 回复  |  直到 9 年前
        1
  •  2
  •   AshMenhennett    9 年前

    您可以使用错误回调。

    return this.$http.post(url, data).then((response) => {
        // success, do success logic
    }, (response) => {
        // redirect to error view
    });
    
    推荐文章