Last active
May 5, 2017 20:30
-
-
Save darrenjennings/f4b3f609630aea07cf45059db4e252f0 to your computer and use it in GitHub Desktop.
Data Driven Vue.js Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
export default class Api { | |
static getUsers() { | |
return axios.get(`https://jsonplaceholder.typicode.com/users`); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class='container'> | |
<p v-if="loading">Loading...</p> | |
<data-table | |
:headerTitle="'Data Driven For Lyfe'" | |
:columns="columns" | |
:data="data" | |
:clickRow="clickRow" | |
v-if="!loading"></data-table> | |
</div> | |
</template> | |
<script> | |
import Api from './Api'; | |
import DataTable from './DataTable'; | |
export default { | |
name: 'Data Driven', | |
components: { | |
DataTable | |
}, | |
data() { | |
return { | |
data: [], | |
loading: true, | |
columns: ['id','name','username', 'email', 'phone', 'website'] | |
}; | |
}, | |
created() { | |
Api.getUsers().then(response => { | |
this.loading = false; | |
this.data = response.data; | |
}, error => { | |
this.loading = false; | |
console.error(error); | |
}); | |
}, | |
methods: { | |
clickRow(el) { | |
console.log(`You clicked row ${el.target.parentElement.id}!`); | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment