RT, there are multiple lines of input in a form. I would like to ask how can all the content be saved in json format and then sent out? I"ve found a lot of methods written by jquery, and I"d like to ask vue how to do this.
I may not be very clear. I am using JSON.stringfy, but the json format I want is more complex. The example is as follows:
{
"Test_number":"name1"
"list":[
{
"user_id":[100, 200,300],
"group_number":"1"
},
{
"user_id":[400,500],
"group_number":"2"
}
]
}
where I will have four input boxes corresponding to group_number (1), group_number (2), user_id (1) and user_id (2). Enter one value for the first two input, and enter more than one for the last two, for example, paste 100200300 into the input of user_id at one time. I need to save these in array format, while the entire form is a large list array containing these two object. The main reason is that the format involves arrays, so I don"t know how to operate it. Want to know how to write v-model at the input, and then what is the format of the data return part.
Front end:
<form action="" :model="test1" ref="test1" method="post" id="test1" enctype="multipart/form-data">
<label>Test number</label>
<input type="text" name="test_number" id="test_number" v-model="test1.test_number">
<input type="text" v-model="test1.group_number" placeholder="group_number 1">
<input type="text" v-model="test1.user_id" placeholder="user_id 1">
<input type="text" v-model="test1.group_number" placeholder="group_number 2">
<input type="text" v-model="test1.user_id" placeholder="user_id 2">
<button v-on:click="submitList($event)" class="btn the-submit">submit</button>
</form>
data section:
data(){
return{
dataSet:{
test_number:"",
list:[
{
user_id:[],
group_number:""
},
{
user_id:[],
group_number:""
}
]
}
}
}
axios post:
submitWhiteList(event){
event.preventDefault();
let formData = new FormData();
formData.append("dataSet", dataSet);
let config = {
headers:{"Content-Type":"multipart/form-data"}
};
axios.post("/upload", formData
,config
).then(rst =>{
........
}
}
this is the method I use at the moment, and it must be something less.