Skip to content

Instantly share code, notes, and snippets.

@darrenjennings
Last active May 5, 2017 20:30
Show Gist options
  • Save darrenjennings/f4b3f609630aea07cf45059db4e252f0 to your computer and use it in GitHub Desktop.
Save darrenjennings/f4b3f609630aea07cf45059db4e252f0 to your computer and use it in GitHub Desktop.
Data Driven Vue.js Example
import axios from 'axios';
export default class Api {
static getUsers() {
return axios.get(`https://jsonplaceholder.typicode.com/users`);
}
}
<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