Error in render: "TypeError: Cannot read property '' of undefined"
[Vue 警告]:渲染错误:"TypeError: Cannot read property \\'object\\' of undefined"
这个 v-for 很好用
1 2 3 4 5 6 7 8 | <p class="horizontal-menu-item-link" v-on:mouseover="isMouseover1=true" v-on:mouseleave="isMouseover1=false">{{item.name}}</p> <h2 class="horizontal-menu-title robot-header-horizontalMenu-title"> <i class="icon-container gg-icon gg-icon-menu-phone"> Elektronik Kategorisi <i class="gg-icon gg-icon-pagination-arrow-right"> |
这里出错了。
1 2 | <h3 class="sub-title robot-header-horizontalMenu-subTitle" v-for="(item2, index2) in this.object.topMenuItem1" :key="index2"> {{item2.id}} |
Vue 运行良好。我正在使用 axios 获取数据。并在模板中使用 v-for 显示。我可以轻松获得 topMenu。使用相同的方法获取 topMenuItem1。但是当我在模板中使用 v-for 时,出现打字错误。我的失败在哪里?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | data() { return { //top menü topMenu: null, topMenuItem1: null, topMenuItem2: null, } }, mounted: function mounted () { axios .post("http://localhost:3000/listCategoriesByMID", { id: 1}) .then(response => { this.topMenuItem1 = response.data; console.log("topMenuItem1:" + this.topMenuItem1 +"" + JSON.stringify(this.topMenuItem1)); }); axios .post("http://localhost:3000/listCategoriesByMID", { id: 2}) .then(response => { this.topMenuItem2 = response.data; console.log("topMenuItem2:" + this.topMenuItem2 +"" + JSON.stringify(this.topMenuItem2)); }); axios .post("http://localhost:3000/listMainCategories") .then(response => { this.topMenu = response.data; console.log("topMenu:" + this.topMenu +"" + JSON.stringify(this.topMenu)); }); }, |
一般规则是永远不要在模板中使用
所以把