单页付款(Vue)

时间:2019-08-05 07:08:46

标签: forms vue.js payment

我的水疗应用程序中有如下付款表格:

<form  Method='post' Action='https://pep.shaparak.ir/gateway.aspx'>
    invoiceNumber<input type='text' name='invoiceNumber' v-model='InvoiceNumber' />
    invoiceDate<input type='text' name='invoiceDate' v-model='InvoiceDate' />
    amount<input type='text' name='amount' v-model='Amount' />
    terminalCode<input type='text' name='terminalCode' v-model='TerminalCode' />
    merchantCode<input type='text' name='merchantCode' v-model='MerchantCode' />
    redirectAddress<input type='text' name='redirectAddress' v-model='RedirectAddress' />
    timeStamp<input type='text' name='timeStamp' v-model='TimeStamp' />
    action<input type='text' name='action' v-model='Action' />
    sign<input type='text' name='sign' v-model='Sign' />
    <input type='submit' name='submit' value='Checkout' @click="Checkout()" />
</form>

Checkout: function(){
    axios.get('./api/pasargad').then(response => {
        var vm = this;
        vm.InvoiceNumber = response.data.InvoiceNumber;
        vm.InvoiceDate = response.data.InvoiceDate;
        vm.Amount = response.data.Amount;
        vm.TerminalCode = response.data.TerminalCode;
        vm.MerchantCode = response.data.MerchantCode;
        vm.RedirectAddress = response.data.RedirectAddress;
        vm.TimeStamp = response.data.TimeStamp;
        vm.Action = response.data.Action;
        vm.Sign = response.data.Sign;


        }.bind(vm));
    });
},

当我单击Checkout()函数时,我需要运行以下步骤:

  1. 首先获取数据
  2. 运行表单操作(重定向到网关页面)

但是在此示例中,首先将重定向到具有未知数据的网关!!!

1 个答案:

答案 0 :(得分:0)

首先,应防止默认提交表单,然后在函数内添加另一个Axios调用。 <form v-on:submit.prevent>

checkout应该看起来像这样,

Checkout: function(){
    var vm = this;
    axios.get('./api/pasargad').then(response => {
        vm.InvoiceNumber = response.data.InvoiceNumber;
        vm.InvoiceDate = response.data.InvoiceDate;
        vm.Amount = response.data.Amount;
        vm.TerminalCode = response.data.TerminalCode;
        vm.MerchantCode = response.data.MerchantCode;
        vm.RedirectAddress = response.data.RedirectAddress;
        vm.TimeStamp = response.data.TimeStamp;
        vm.Action = response.data.Action;
        vm.Sign = response.data.Sign;


        }.bind(vm));
    });
    axios.post('https://pep.shaparak.ir/gateway.aspx',vm)
},