【发布时间】:2018-04-17 22:10:18
【问题描述】:
我不知道为什么我的表没有填充 axios,这是我的 DataTable 模板,就像文档一样:
<v-data-table
:headers="headers"
:items="items"
hide-actions
class="slideInDown"
>
<template slot="items" slot-scope="props">
<td>{{ props.item.nombre }}</td>
<td class="text-xs-right">{{ props.item.calle }}</td>
<td class="text-xs-right">{{ props.item.numExterior }}</td>
<td class="text-xs-right">{{ props.item.numInterior }}</td>
<td class="text-xs-right">{{ props.item.codigoPostal }}</td>
</template>
</v-data-table>
这是我的脚本:
<script>
export default {
data () {
return {
items: [
{
nombre: "",
calle: "",
numExterior: "",
numInterior:"",
codigoPostal: "",
}
],
}
},
methods:{
}
created(){
axios.get('http://localhost:58209/api/GetEstaciones',
{
headers:
{
"Authorization": "Bearer "+localStorage.getItem('token')
}
}).then(response => {
this.items = response.data;
}).catch(error => {
console.log(error.response)
});
},
mounted(){
let token = localStorage.getItem('token');
if(token == null){
this.$router.push('/');
}
},
}
</script>
但是该表没有填充,当我在 Visual Studio 中调试我的 WebAPI 时,即使使用 Postman,它也在使用 Get 方法。在我的脚本中,我省略了 heders[],我只显示项目。
在这样的邮递员节目中:
"calle": "AVENIDA BLA",
"numExterior": 121,
"numInterior": 2,
"codigoPostal": 123456,
"nombre": "ASDFGGHJKL"
【问题讨论】:
-
你的控制台有错误吗?
-
@Hammerbot 只显示未定义,但我重写了我的 Get 方法,现在它正在工作。
-
axios.get('localhost:58209/api/GetEstaciones', { headers:{ "Authorization": "Bearer "+localStorage.getItem('token') } }) .then(response => { console. log(response) this.items = response.data; }) .catch(error => { console.log(error.response) });
标签: vue.js axios vuetify.js