I have the following vue.js code using django as a backend.
The response is coming through fine, but I can't seem to set the variable properly.
Am I doing something wrong with the assignment?
Thanks
<script>
import axios from 'axios'
//Datatable
export default {
data () {
return {
items: [],
}
mounted () {
this.getItems()
},
methods: {
getItems() {
const newLocal='http://127.0.0.1:8000/items/'
axios({
method: 'get',
url: newLocal,
auth: {
username: 'login',
password: 'pass'
}
}).then(response => {
let result = [];
result = response.data;
console.log(response.data);
console.log("Data length: " + response.data.length); /// Returns '7'
console.log("Result length: " + result.length); /// Returns '7'
this.items = result;
console.log("Item length #1: " + this.items.length) /// Returns '7'
})
console.log("Item length #2: " + this.items.length) /// **Returns '0' ???**
},