简体   繁体   English

在 Vue 组件上出现错误“无法将未定义或 null 转换为对象”

[英]Getting an error “Cannot convert undefined or null to object” on Vue component

Getting an error “Cannot convert undefined or null to object” on this VueJs Slider.在此 VueJs Slider 上收到错误“无法将未定义或 null 转换为对象”。 It is working here http://novo.evbox.com/ (Its the first component on the page).它在这里工作http://novo.evbox.com/ (它是页面上的第一个组件)。 The functionality works but I would like to solve the error in the console.该功能有效,但我想解决控制台中的错误。 Does anyone have any insights?有没有人有任何见解? Note: I have removed some code for brevity.注意:为简洁起见,我删除了一些代码。

<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>
.then(response => {
  if(response.data && typeof response.data.data === 'object') {
    this.slide = Object.values(response.data.data)
  }
})

I think this will solve the issue我认为这将解决问题

.then(response => {
  if(response.data && response.data.data) {
    this.slider = response.data.data
    this.slide = Object.values(this.slider)
  }
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 渲染错误:“TypeError:无法在 vue js 中将未定义或 null 转换为对象”? - Error in render: “TypeError: Cannot convert undefined or null to object” in vue js? 数据()中的Vue警告错误“类型错误:无法将未定义或空值转换为对象” - Vue warning Error in data() "TypeError: Cannot convert undefined or null to object" 错误:无法将未定义或 null 转换为 object - Error: Cannot convert undefined or null to object 错误TypeError:无法将未定义或null转换为对象 - error TypeError: Cannot convert undefined or null to object 无法将未定义或空值转换为对象的错误 - Error with Cannot convert undefined or null to object 反应:错误:无法将未定义或 null 转换为 object - React: error: Cannot convert undefined or null to object 无法将未定义或null转换为对象 - Cannot convert undefined or null to object ReactJS 错误 TypeError:无法将 undefined 或 null 转换为对象 - ReactJS error TypeError: Cannot convert undefined or null to object UglifyJs引发错误:无法将未定义或null转换为对象 - UglifyJs throws error: Cannot convert undefined or null to object json数据错误未捕获的TypeError:无法将未定义或null转换为对象 - json data error Uncaught TypeError: Cannot convert undefined or null to object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM