简体   繁体   English

数据()中的Vue警告错误“类型错误:无法将未定义或空值转换为对象”

[英]Vue warning Error in data() "TypeError: Cannot convert undefined or null to object"

does anybody know how I can get rid of this warning?有谁知道我怎样才能摆脱这个警告? I guess it happens because I try to do something with an undefined object?我猜这是因为我试图用未定义的对象做某事? Any help would be very much appreciated!任何帮助将不胜感激! Thank you!谢谢! Here is my code:这是我的代码:

 <v-card class="ma-3 pa-3" v-for="item in state.monitorAll[0]" v-bind:key="item.countdown"> <v-row> <div class="ma-3">Minuten bis zum nächsten Halt: <v-avatar class="ml-2 blue white--text">{{ item.departureTime.countdown }}</v-avatar></div> <v-avatar v-if="typeof item.vehicle == 'undefined'" class="ma-3 ml-5 green"><v-icon class="white--text">accessible</v-icon></v-avatar> </v-row> </v-card> <script> import axios from 'axios' import {onMounted, reactive} from '@vue/composition-api' export default { name: 'App', setup() { let state = reactive({ wlData: '', monitorAll: [], }) async function showData() { let config = { headers: { 'Accept': 'application/json', 'Access-Control-Allow-Origin': 'http://localhost:8080', 'Content-Type': 'text/plain' } } const wlData = await axios.get('http://localhost:8080/ogd_realtime/monitor?rbl=832', config); state.wlData = wlData.data.data['monitors']; state.monitorAll = state.wlData.map(monitor => monitor.lines[0].departures.departure); } let startLoad = onMounted(() => { console.log('component is mounted!'); showData(); }) return { state, showData, startLoad, } } }; </script>

I figured it out.我想到了。 It was the onMounted that caused the problem.是 onMounted 导致了问题。 I guess it is because the onMounted is called before there is any value in the showData().我猜这是因为在 showData() 中有任何值之前调用了 onMounted。 I am not sure.我不确定。 I deleted;我删除了;

let startLoad = onMounted(() => { console.log('component is mounted!'); showData(); }) let startLoad = onMounted(() => { console.log('组件已安装!'); showData(); })

and just called showData() directly after the async function showData() is being created.并在创建异步函数 showData() 后直接调用 showData() 。 I have no idea why this works and I guess it is not the best way to handle it, but at least I lost my warning!我不知道为什么会这样,我想这不是处理它的最佳方法,但至少我失去了警告!

声明:本站的技术帖子网页,遵循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? json数据错误未捕获的TypeError:无法将未定义或null转换为对象 - json data error Uncaught TypeError: Cannot convert undefined or null to object 错误TypeError:无法将未定义或null转换为对象 - error TypeError: Cannot convert undefined or null to object ReactJS 错误 TypeError:无法将 undefined 或 null 转换为对象 - ReactJS error TypeError: Cannot convert undefined or null to object 服务器错误:类型错误:无法将未定义或 null 转换为 object - Server Error : TypeError: Cannot convert undefined or null to object 在 Vue 组件上出现错误“无法将未定义或 null 转换为对象” - Getting an error “Cannot convert undefined or null to object” on Vue component 类型错误:无法将 undefined 或 null 转换为对象 - TypeError: Cannot convert undefined or null to object TypeError:无法在反应中将未定义或 null 转换为 object - TypeError: Cannot convert undefined or null to object in react 类型错误:无法将未定义或空值转换为对象 javascript - TypeError : Cannot convert undefined or null to object javascript Javascript:TypeError:无法将未定义或null转换为对象 - Javascript: TypeError: Cannot convert undefined or null to object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM