dynamically loops through an object through v-for, adds hidden elements to the form, and then submits it through document.getElementById ("form"). Submit ()
), finding that another page does not receive parameters.
and elements created in the document.createElement ("input")
mode can receive parameters.
the strangest thing is that both v-for and document.createElement () can see the contents through console.log (form). Only one can receive the parameter and the other can"t.
can"t forms created by v-for be submitted through document.getElementById ("form"). Submit ()
)?
v-for mode
<form method="post" id="cgForm" style="display: none;" :action="formData != null ? formData.url : """>
<input type="hidden" v-for="(v, k) in formData" v-if="k != "url"" :value="v" :name="k"/>
</form>
<script type="text/babel">
this.formData = data.data;
let form = document.getElementById("cgForm");
console.log(form); // form, form, action "/" url
form.submit();
</script>
normal form form
<form method="post" id="cgForm" style="display: none;"></form>
<script type="text/babel">
this.formData = data.data;
let form = document.getElementById("cgForm");
for(let p in this.formData){
if(p != "url"){
let input = document.createElement("input");
input.setAttribute("name", p);
input.setAttribute("value", this.formData[p]);
form.append(input);
}
}
form.action = data.data.url;
form.submit();
</script>