<script>
let vm = new Vue({
el: '#app',
data: function () {
return {
info: null,
loading: true,
errored: false,
name: null,
description: null,
}
},
methods: {
saveCategory: function () {
let _data = {
'name': this.name,
'description': this.description,
'status': true
}
axios
.post('https://gorest.co.in/public-api/categories/', _data, {
headers: {"Content-type": "application/json; charset=UTF-8","Authorization": "Bearer AccessToken"}
})
.then(response => {
this.info = response
console.log(response)
this.getCategory()
})
.catch(error => {
console.log(error)
this.errored = true
})
},
getCategory: function () {
axios
.get('https://gorest.co.in/public-api/categories')
.then(response => {
this.info = response.data.data
})
.catch(error => {
console.log(error)
this.errored = true
})
.finally(() => this.loading = false)
}
},
mounted () {
// panggil method getCategory()
this.getCategory()
}
})
</script>