In my vue component I have a data array
data: {
categories: [{id:1, title: "category 1"},{id:2, title: "category 2"}]
}
and I'm trying to load this in as a data argument in an axios call
axios({
method: 'get',
url: //testURL,
data: {
categoryCall: this.categories
}
}).then(function (response){
console.log(response);
}).catch(function (error){
console.log(error.response);
});
but I'm getting a 400 bad request code where it tells me that argument 1 should be an array and null is given.
Am I not properly passing in the already established array in the axios call? Where am I going wrong?
var vm =
new Vue({
el: "#app",
data: {
categories: [
{id:1, title: "category 1"},
{id:2, title: "category 2"}
]
},
methods: {
submit_axios(){
axios({
method: 'get',
url: //test,
data: {
categories: this.categories
}
}).then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error.response);
});
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<button @click="submit_axios()">Search</button>
</div>