本文實(shí)例講述了vue-for循環(huán)嵌套操作。分享給大家供大家參考,具體如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> *{ margin: 0; padding: 0; list-style: none; } </style> </head> <body> <table id="app" border="1" cellspacing="0" cellpadding="0"> <tr> <td>父循環(huán)第幾次</td> <td>子循環(huán)第幾次</td> <td>json的第幾條數(shù)據(jù)</td> <td>數(shù)值</td></tr> <tbody v-for="x,index in parentList"> <tr v-for="i,index2 in x.childList"> <td>{{index}}</td> <td>{{index2}}</td> <td>{{i.index}}</td> <td>{{i.childName}}</td> </tr> </tbody> </table> </body> <script src="https://cdn.bootcss.com/vue/2.4.4/vue.min.js"></script> <script> const app=new Vue({ el:"#app", data:{ parentList: [{ childList: [{ index: 1, childName: "第一個(gè)節(jié)點(diǎn)" }, { index: 2, childName: "第一個(gè)節(jié)點(diǎn)" }, { index: 3, childName: "第一個(gè)節(jié)點(diǎn)" }, { index: 4, childName: "第一個(gè)節(jié)點(diǎn)" }, { index: 5, childName: "第一個(gè)節(jié)點(diǎn)" }] }, { childList: [{ index: 6, childName: "第二個(gè)節(jié)點(diǎn)" }, { index: 7, childName: "第二個(gè)節(jié)點(diǎn)" }, { index: 8, childName: "第二個(gè)節(jié)點(diǎn)" }, { index: 9, childName: "第二個(gè)節(jié)點(diǎn)" }, { index: 10, childName: "第二個(gè)節(jié)點(diǎn)" }] }, { childList: [{ index: 11, childName: "第三個(gè)節(jié)點(diǎn)" }, { index: 12, childName: "第三個(gè)節(jié)點(diǎn)" }, { index: 13, childName: "第三個(gè)節(jié)點(diǎn)" }, { index: 14, childName: "第三個(gè)節(jié)點(diǎn)" }, { index: 15, childName: "第三個(gè)節(jié)點(diǎn)" }] }] } }) </script> </html>
這里使用在線HTML/CSS/JavaScript代碼運(yùn)行工具:http://tools.jb51.net/code/HtmlJsRun測(cè)試上述代碼,可得如下運(yùn)行結(jié)果:
希望本文所述對(duì)大家vue.js程序設(shè)計(jì)有所幫助。
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com