I am learning vue.js for the first time tonight and I can't wrap my head around why when I set a "list" array in the data function, i cannot change it in a method below. I have the following code and my template still spits out my original {name: 'daniel'}, {name: 'lorie'} variable.
My http call is definitely being made as i can see an array of like 100 users in the network tab, but "this.list = data" is not resetting my data variable
<template>
<pre>{{list}}</pre>
</template>
<script>
export default {
data () {
return {
list: [{name: 'daniel'}, {name: 'lorie'}]
}
},
created () {
this.fetchContactList()
},
methods: {
fetchContactList () {
this.$http.get('https://jsonplaceholder.typicode.com/users', (data) => {
this.list = data
})
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss">
ul.user-list {
background: #fafafa;
border:1px solid #ebebeb;
padding:40px;
li {
list-style: none;
display: block;
margin-bottom:10px;
padding-bottom:10px;
border-bottom:1px solid #ebebeb;
}
}
</style>