在 Vue 组件上收到错误“无法将未定义或空转换为对象”
2020-06-15
1204
在此 VueJs Slider 上获取错误“无法将未定义或 null 转换为对象”。它在这里工作 http://novo.evbox.com/ (它是页面上的第一个组件)。该功能有效,但我想解决控制台中的错误。有人有什么见解吗? 注意:为了简洁起见,我删除了一些代码。
<template>
<div id="vue-slider">
<div
id="button-toggle-container"
class="button-toggle-container flex justify-center justify-between mt3 mb4 mx-auto"
>
<button
class="button-toggle"
v-for="(slidePanelKey, mainIndex) in Object.keys(slider)"
:id="slidePanelKey"
:key="mainIndex"
@click="setActivePanel(mainIndex)"
:class="{active: mainIndex == activeButtonIndex}"
>{{ slidePanelKey }}</button>
</div>
</div>
</template>
<script>
import axios from "axios";
export default {
name: "slider",
props: {
slide: Object
},
data() {
return {
slider: null,
retrieved: {
slider: false
}
}
},
mounted: function () {
// Retrieve slides data.
axios
.get(
"/api/?hash=API-KEY&type=slider" +
"&context=" + this.getContext()
)
.then(response => {this.slider = response.data.data
this.slide = Object.values(this.slider)
})
// eslint-disable-next-line
.catch(error => console.log(error))
},
},
};
</script>
2个回答
.then(response => {
if(response.data && typeof response.data.data === 'object') {
this.slide = Object.values(response.data.data)
}
})
ebyte
2020-06-15
我认为这将解决问题
.then(response => {
if(response.data && response.data.data) {
this.slider = response.data.data
this.slide = Object.values(this.slider)
}
})
thealpha93
2020-06-15