ImC0der
ImC0der

Reputation: 318

Error in render: "TypeError: Cannot read property '' of undefined"

[Vue warn]: Error in render: "TypeError: Cannot read property 'object' of undefined"

this v-for works nice

                  <div class="horizontal-menu-item robot-header-horizontalMenu-menuItem" v-for="(item, index) in this.topMenu" :key="index">
                        <p class="horizontal-menu-item-link" v-on:mouseover="isMouseover1=true" v-on:mouseleave="isMouseover1=false">{{item.name}}</p>
                        <div class="horizontal-menu-detail" v-bind:style="isMouseover1 ? 'display: block' : 'display: none;'" v-on:mouseover="isMouseover1=true" v-on:mouseleave="isMouseover1=false">
                            <div class="horizontal-menu-title-container gg-d-offset-1 gg-d-22 gg-w-22">
                                <h2 class="horizontal-menu-title robot-header-horizontalMenu-title">
                                    <i class="icon-container gg-icon gg-icon-menu-phone"></i>
                                    <a href="https://www.gittigidiyor.com/elektronik" title="Elektronik Kategorisi">
                                        Elektronik Kategorisi
                                        <i class="gg-icon gg-icon-pagination-arrow-right"></i>
                                    </a>
                                </h2>
                            </div>
                            <div class="horizontal-menu-column gg-d-offset-1 gg-d-7 gg-w-5 gg-uw-4" >
                                <div class="robot-header-horizontalMenu-subItem sub-item">

I got error here.

                                    <h3 class="sub-title robot-header-horizontalMenu-subTitle" v-for="(item2, index2) in this.object.topMenuItem1" :key="index2">
                                        <a class="sub-title-link" href="https://www.gittigidiyor.com/cep-telefonu-ve-aksesuar" title="Cep Telefonu ve Aksesuar">{{item2.id}}</a>
                                    </h3>
                                </div>
                            </div>
                        </div>
                    </div>

Vue works nice. I am getting datas with axios. And using v-for show in template. I can get topMenu easily. Using same method getting topMenuItem1. But when I use v-for in template, got typer error. Where is my fail?

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));
            });
    },

Upvotes: 0

Views: 1360

Answers (1)

ellisdod
ellisdod

Reputation: 1734

The general rule is to never use this in the template: possible explanation

So change ths.object.topMenuItem1 to topMenuItem1

Upvotes: 2

Related Questions