您好,登錄后才能下訂單哦!
怎么在vue中實現多次循環操作?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
Vue是一套用于構建用戶界面的漸進式JavaScript框架,Vue與其它大型框架的區別是,使用Vue可以自底向上逐層應用,其核心庫只關注視圖層,方便與第三方庫和項目整合,且使用Vue可以采用單文件組件和Vue生態系統支持的庫開發復雜的單頁應用。
需求:有以下一個數組,想將其對象里的信息展示出來,而且還要把對象下面的數組的具體信息也展示出來。v-for可以實現循環,但是能否再下一級進行渲染呢?答案是可以的。
list: [{ "scheme_id": "1", "scheme_sn": "2018031416442200001", "scheme_name": "測試支付寶", "type": "", "field_id": "0", "user_id": "5", "mother_id": "0", "content": "測試支付寶", "program_id": "1,2", "status": "1", "range": "1", "obj": "5", "add_time": "2018-03-14 16:44:22", "is_handsel": "2", "atten_del": "", "up_time": null, "obj_phone": "13521121232", "programs": [{ "program_id": "1", "reserve": "99701", "program_name": "測試支付寶1", "price": "0.0100", "sale_num": "200" }, { "program_id": "2", "reserve": "4895", "program_name": "阿薩打算", "price": "0.0200", "sale_num": null }] }, { "scheme_id": "2", "scheme_sn": "2018031416512800002", "scheme_name": "阿散發撒", "type": "", "field_id": "0", "user_id": "5", "mother_id": "0", "content": "阿斯達", "program_id": "2,3", "status": "2", "range": "1", "obj": "5", "add_time": "2018-03-14 16:51:28", "is_handsel": "2", "atten_del": "", "up_time": null, "obj_phone": "13521121232", "programs": [{ "program_id": "2", "reserve": "4895", "program_name": "阿薩打算", "price": "0.0200", "sale_num": null }, { "program_id": "3", "reserve": "10", "program_name": "測試多個程序方案贈送1", "price": "0.0000", "sale_num": null }] }]
HTML部分:
<div id="app"> <div v-for ="item in list"> <p>{{item.scheme_sn}}</p> <p v-for="items in item.programs">程序id {{items.program_id}}</p> <p v-for="items in item.programs">程序名稱 {{items.program_name}}</p> </div> </div>
先循環大的list 然后再用items in item.programs
去循環對象里面的數組
完整測試示例:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>www.jb51.net vue多次循環</title> <style> *{ margin: 0; padding: 0; list-style: none; } </style> </head> <body> <div id="app"> <div v-for ="item in list"> <p>{{item.scheme_sn}}</p> <p v-for="items in item.programs">程序id {{items.program_id}}</p> <p v-for="items in item.programs">程序名稱 {{items.program_name}}</p> </div> </div> </body> <script src="https://cdn.bootcss.com/vue/2.4.4/vue.min.js"></script> <script> const app=new Vue({ el:"#app", data:{ list: [{ "scheme_id": "1", "scheme_sn": "2018031416442200001", "scheme_name": "測試支付寶", "type": "", "field_id": "0", "user_id": "5", "mother_id": "0", "content": "測試支付寶", "program_id": "1,2", "status": "1", "range": "1", "obj": "5", "add_time": "2018-03-14 16:44:22", "is_handsel": "2", "atten_del": "", "up_time": null, "obj_phone": "13521121232", "programs": [{ "program_id": "1", "reserve": "99701", "program_name": "測試支付寶1", "price": "0.0100", "sale_num": "200" }, { "program_id": "2", "reserve": "4895", "program_name": "阿薩打算", "price": "0.0200", "sale_num": null }] }, { "scheme_id": "2", "scheme_sn": "2018031416512800002", "scheme_name": "阿散發撒", "type": "", "field_id": "0", "user_id": "5", "mother_id": "0", "content": "阿斯達", "program_id": "2,3", "status": "2", "range": "1", "obj": "5", "add_time": "2018-03-14 16:51:28", "is_handsel": "2", "atten_del": "", "up_time": null, "obj_phone": "13521121232", "programs": [{ "program_id": "2", "reserve": "4895", "program_name": "阿薩打算", "price": "0.0200", "sale_num": null }, { "program_id": "3", "reserve": "10", "program_name": "測試多個程序方案贈送1", "price": "0.0000", "sale_num": null }] }] } }) </script> </html>
使用在線HTML/CSS/JavaScript代碼運行工具:http://tools.jb51.net/code/HtmlJsRun測試上述代碼,可得如下運行效果:
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。