【发布时间】:2021-12-31 07:40:37
【问题描述】:
调用api后设置from值后如何自动提交表单
我希望表单在从 api 成功获取值后自动提交,
我使用了 $refs.form.submit(),但是,它没有按预期工作,
一个请求被发送到:http://localhost:3200/login-saml (FE)
虽然预期的 url 是:localhost:8080/login (BE)
<template>
<!-- Sing in Form -->
<section class="sign-in" style="padding-top: 65px">
<div class="container">
<form v-bind:action="urlLogin" method="post" ref="form">
<input type="text" id="SAMLRequest" name="SAMLRequest" v-model="SAMLRequest">
<input type="submit" value="Submit">
</form>
</div>
</section>
</template>
<script>
import axios from 'axios';
export default {
name: 'LoginPage',
data() {
return {
urlLogin: '',
SAMLRequest: ''
}
},
mounted() {
axios.get(`http://localhost:8080/rest/v2/sso/loginInfo`)
.then(response => {
this.urlLogin = response.data.urlLogin;
this.SAMLRequest = response.data.samlrequest;
this.$refs.form.submit();
})
.catch(e => {
console.log(e)
})
}
}
</script>
【问题讨论】:
-
有什么问题?你有错误吗?还是别的什么?
-
@MahEs 我已经用错误详情更新了问题,希望你能帮我检查一下
-
您的 axios 调用是否返回 200 ?你能提供你的回应日志吗?我不是usre,但我认为问题可能是您的axios url是本地url。
-
@MahEs axios 返回 200,如果我删除它,一切正常。$refs.form.submit();并手动点击
标签: javascript vue.js vuejs2 vue-component