javascript - New to Vue, how to use the v-for directive in components
ringa_lee
ringa_lee 2017-05-19 10:37:59
0
2
618

code show as below:

Vue.component('child-i',{ 
props:['msg','datato'],
template:'<h1>{{msg.title}}</h1>'+
        '<table>'+
        '<tbody>'+
            '<tr v-for="to in todata" :datato="to">'+
                '<td>{{datato.tile1}}</td>'+
                '<td>{{datato.tile2}}</td>'+
                '<td>{{datato.tile3}}</td>'+
            '</tr>'+
            '</tbody>'+
        '</thead>'
});

Second code

var datas = new Vue({
el:"#app",
data:{
    parameter:{title:"hello vue js"},
    todata:[{
        tile1:"aaa",
        tile2:"www",
        tile3:"sss",
    },{
        tile1:"aaa",
        tile2:"www",
        tile3:"sss",
    },{
        tile1:"aaa",
        tile2:"www",
        tile3:"sss",
    }]
}
});

HTML

<p id="app" >
    <child-i :msg="parameter"></child-i>
</p>

In fact, what I want to do is very simple. I want to use the v-for instruction to dynamically construct a set of tr and td table tags inside the subcomponent. When I run it, the browser does not report an error, but there is no error in the tag. Any tags about tr and td, did I write them wrong? , I hope the master can give some advice or provide a demo for reference

ringa_lee
ringa_lee

ringa_lee

reply all(2)
阿神

You have already sent the msg and also the todata...

世界只因有你

HTML

<p id="app" >
    <child-i :msg="parameter" :datato="todata"></child-i>
</p>

JS

Vue.component('child-i',{
props:['msg','datato'],
template:'<h1>{{msg.title}}</h1>'+
        '<table>'+
        '<tbody>'+
            '<tr v-for="to in datato">'+
                '<td>{{to.tile1}}</td>'+
                '<td>{{to.tile2}}</td>'+
                '<td>{{to.tile3}}</td>'+
            '</tr>'+
            '</tbody>'+
        '</thead>'
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template