【发布时间】:2020-12-26 07:28:19
【问题描述】:
大家好,所以我无法将此 API 中的数据显示到我的 Vue 引导表中。
它给了我这个错误: " 属性或方法 "products" 未在实例上定义,但在渲染期间被引用。通过初始化属性,确保此属性是反应性的,无论是在数据选项中还是对于基于类的组件。 "
问题出在我的 App.vue 中,我在实例上定义了产品。所以我不明白为什么它会抛出这个错误。
这是我的 App.vue
<template>
<div id="app" class="container">
<PagTable :products="products"/>
</div>
</template>
<script>
import Vue from 'vue';
import axios from 'axios'
import PagTable from './components/PagTable.vue'
const vshredAPI = 'https://app.vshred.com/api/offers?include=images&per_page=25&page=1'
Vue.use(axios)
export default {
name:"app",
components: {
PagTable
},
data(){
return {
Page:1,
products: []
}
},
mounted() {
this.fetchData()
},
methods: {
fetchData () {
axios.get(vshredAPI + this.page)
.then(({data}) => {
this.products= data
})
}
}
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
分页表组件
<template>
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">id</th>
<th scope="col">Name</th>
<th scope="col">Image</th>
<th scope="col">Price</th>
<th scope="col">Purchase</th>
</tr>
</thead>
<tbody>
<tr v-for="product in products" :key="product.id">
<th scope="row">1
{{ products.indexOf(product) + 1 }}
</th>
<td>{{product.id}}</td>
<td>{{product.name}}</td>
<td>
<img v-if="product.image.url" class="image" :src="product.image.url"/>
</td>
</tr>
</tbody>
</table>
</template>
<script>
export default {
name: 'PageTable',
props: {
proudcuts: Array
}
}
</script>
<style scoped>
</style>
如果有人可以帮助我或指导我,将非常感谢
【问题讨论】:
标签: api vue.js axios bootstrap-vue