How does vue put the contents of two tables in one table?

means that there are two tables, a commodity table and a version table. To put the contents of these two tables into a table, each row is a commodity name, and the attributes in each row include multiple version names. The specific table is similar to the following

.

I wrote the code, but reported an error TypeError: Cannot read property "ver_list" of undefined,. I"m sure it"s not because the v-for version is wrong, because if I delete the v-for product on th and replace it with the v-for version on ul, how should I change it?

the data goes like this
goods_list [{goods_id:1,goods_name:" book"} {goods_id:1,goods_name:" pen"}]
ver_list [{ver_id:1,goods_id:2,ver_name:" pencil"} {ver_id:2,goods_id:2,ver_name:" pen"} {ver_id:3,goods_id:1,ver_name:" classics"}]

the code I wrote is

    <template id="list_box">
    <div>
        <table class="table table-hover">
            <tr>
                <th>ID</th>
                <th></th>
                <th></th>
                <th></th>
            </tr>
            <!--  -->
            <tr v-for="(info,index) in this.$parent.goods_list"  >
                <td>{{index+1}}</td>
                <td>{{info.goods_name}}</td>
                <td>
                    <!-- 
                    TypeError: Cannot read property "ver_list" of undefined 
                    -->
                    <ul v-for="(info1,index1) in this.$parent.ver_list" 
                        v-if="info1.goods_id==info.goods_id">
                        <li>{{info1.ver_name}}</li>
                    </ul>
                </td>
                <td>
                    <a href=""></a>
                </td>
            </tr>
        </table>
    </div>
</template>

structure is

    new Vue({
        router,
        el:".container",
        data:{
            goods_list:[],
            ver_list:[],
        }, 
        created(){
            this.goods_list = JSON.parse(localStorage.getItem("goods_list"))
            if (this.goods_list==null) {
                this.goods_list = []
            }
            this.ver_list = JSON.parse(localStorage.getItem("ver_list"))
            if (this.ver_list==null) {
                this.ver_list = []
            }
            console.log(this.ver_list)
        },
    })

this is how router is defined

                {
                path:"/",
                component:{  
                    template:"-sharplist_box",    
                } 
            }
Mar.04,2021

can I post your data, because according to the error message, there should be no ver_list attribute in your data

< hr >

the reason should be double for this pointing question
I changed it. Look at
. The main reason is that this.$parent is treated as a variable. Now you can achieve the effect you want.

path:'/add',
                    component:{
                        data(){
                            return {
                                goods_id:'',
                                goods_name:'',
                                ver_id:'',
                                ver_name:'',
                                ver_introduction:'',
                                color_name:'',
                                goods_price:'',

                                ver_list1:[],
                                color_list:[],
                                $parent: this.$parent
                            }
                            
                        },
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.bootcss.com/vue/2.4.4/vue.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/vue-router/2.7.0/vue-router.min.js"></script>
    <style>
        .ver_box li{width: 33%;float: left;}
        .border{border: 1px solid black}
    </style>
</head>
<body>

    <div class="container">
        <h2></h2>
        <router-link to="/"  class="btn btn-primary"></router-link>
        <router-link to="/add"  class="btn btn-info"></router-link>

        <router-view></router-view>
    </div>
    <template id="list_box">
        <div>
            <table class="table table-hover">
                <tr>
                    <th>ID</th>
                    <th></th>
                    <th></th>
                    <th></th>
                </tr>
                
                <tr v-for="(info,index) in $parent.goods_list"  >
                    <td>{{index+1}}</td>
                    <td>{{info.goods_name}}</td>
                    <td>
                        
                    <!-- -->
                        <p v-model="1+1">

<ul v-for="(info1,index1) in $parent.ver_list"> <li>{{info1.ver_name}}</li> </ul> </td> <td> <a href=""></a> </td> </tr> <!-- ver_list --> <tr v-for="(info1,index1) in $parent.ver_list" > <td>{{index1+1}}</td> <td>{{info1.ver_name}}</td> <td> </td> <td> <a href=""></a> </td> </tr> </table> </template> <template id="add_box"> <div> <form action="" class="from"> <div class="form-group"> <label ></label> <input type="text" class="form-control" v-model="goods_name"></div> <div class="form-group"> <label > <a @click="add_version()" class="btn btn-info"></a> </label> <ul class="ver_box"> <li v-for="(ver_info,index) in ver_list1"> {{index+1}}: <input type="text" v-model="ver_info.ver_name"> </li> </ul> </div> <div class="form-group" style="clear: both"> <input type="button" :disabled="goods_name=='' " class="btn btn-primary" value="" v-on:click="save()"></div> </form> </div> </template> </template> <script type="text/javascript"> var router = new VueRouter({ routes:[ { path:'/add', component:{ data(){ return { goods_id:'', goods_name:'', ver_id:'', ver_name:'', ver_introduction:'', color_name:'', goods_price:'', ver_list1:[], color_list:[], $parent: this.$parent } }, methods:{ save:function () { debugger var goods_name = this.goods_name var ver_list = this.ver_list1 var n=ver_list.length this.$parent.goods_list.push({ goods_name }) for(var i=0;n>0;iPP){ console.log(ver_list[i].ver_name) this.$parent.ver_list.push({ ver_name:ver_list[i].ver_name }) n-- } localStorage.setItem('goods_list',JSON.stringify(this.$parent.goods_list)) localStorage.setItem('ver_list',JSON.stringify(this.$parent.ver_list)) this.$router.push('/') }, add_version:function () { // this.ver_list1.push({ ver_name:'', }) }, }, template:'-sharpadd_box' } }, { path:'/', component:{ template:'-sharplist_box', } } ] }) new Vue({ router, el:".container", data:{ goods_list:[], ver_list:[] }, created(){ debugger this.goods_list = JSON.parse(localStorage.getItem('goods_list')) if (this.goods_list==null) { this.goods_list = [] } this.ver_list = JSON.parse(localStorage.getItem('ver_list')) if (this.ver_list==null) { this.ver_list = [] } console.log(this.ver_list) }, methods:{ } }) </script> </body> </html>
Menu