Problems with dynamic submission of form forms by vuejs

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>
Mar.28,2021

vuejs has a lifecycle. When your js is running, the dom has not been fully generated. You can submit the form in the vue lifecycle mounted and attach the link https://cn.vuejs.org/v2/api/-sharp.

.
Menu