I have 2 input boxes for weights and values, and I can then click a button to automatically create more. This part is working fine.
The problem now is that the server expects a JSON formdata request containing array of ints, rather than strings.
This is how the postdata should look like:
{"stuff": {"weights": [2, 5, 3], "values": [654, 23, 3]}}
This is what it ends up looking like:
{"stuff": {"weights": ["2", "5", "3"], "values": ["654", "23", "3"]}}
I have tried to search how to set data array type to int, how to save v-model as int, etc.
I believe this is all the relevant code:
<template>
..
<div v-for="(weight, index) in weights">
<div>
<label for="w">weight:</label>
<input v-model="weights[index]">
<label for="v">value:</label>
<input v-model="values[index]">
</div>
</div>
..
</template>
<script>
export default {
data () {
return {
weights: [],
values: []
}
},
methods: {
solve: function () {
var formData = {
stuff: {
weights: this.weights,
values: this.values
}
}
axios.post('http://localhost:8000/my/api/url', formData).then(response => {
console.log(response)
}).catch(e => {
console.log(e)
})
},
...
</script>