Skip to content

Instantly share code, notes, and snippets.

@marcelojunior
Last active October 31, 2017 14:32
Show Gist options
  • Save marcelojunior/cc8ac501d97f470ca2dbdc7eb3af49d2 to your computer and use it in GitHub Desktop.
Save marcelojunior/cc8ac501d97f470ca2dbdc7eb3af49d2 to your computer and use it in GitHub Desktop.
<template>
<md-layout>
<md-card>
<md-table>
<md-table-header>
<md-table-row>
<md-table-head v-for="campo in campos" :key="campo.nome">{{ campo.descricao }}</md-table-head>
</md-table-row>
</md-table-header>
<md-table-body>
<md-table-row v-for="item in lista" :key="item.id">
<md-table-cell v-for="campo in campos" :key="campo.nome">{{ item[campo.nome] }}</md-table-cell>
</md-table-row>
</md-table-body>
</md-table>
</md-card>
</md-layout>
</template>
<script>
import axios from 'axios'
export default {
name: 'dinamicos-index',
data () {
return {
campos: [],
lista: [],
path: '',
isMounted: false
}
},
watch: {
// Chama sempre que a rota troca
'$route': 'buscaDados'
},
methods: {
buscaDados () {
this.path = this.$route.params.path
console.log(this.path)
axios.get(this.path).then(resp => {
this.campos = resp.data.campos
this.lista = resp.data.lista
}).catch(resp => {
console.log('erro')
this.campos = []
this.lista = []
})
}
},
mounted () {
this.buscaDados()
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment