微信小程序---数组追加数据的方法 1、list.wxml!--pages/list/list.wxml-- view classcontainer view你好showcontainer/view block wx:for{{list}} wx:keyid !-- 主题 -- view classtopic view classtitle{{item.title}}/view view classdesc{{item.description}}/view !-- 问题列表 -- view classquestion-list block wx:for{{item.questions}} wx:keyid view classquestion {{index 1}}. {{item.content}} /view /block /view /view /block /view2、list.wxss.container { padding: 20rpx; } .topic { margin-bottom: 30rpx; padding: 20rpx; border: 1px solid #eee; border-radius: 10rpx; } .title { font-weight: bold; font-size: 32rpx; } .desc { color: #666; margin: 10rpx 0; } .question { padding: 10rpx 0; border-bottom: 1px dashed #ddd; }3.list.js3.1、data函数data: { list: [] },3.2、load函数this.getList()3.3、添加一个函数getList() { let list this.data.list list.push ({ id: 1, title: Java学习, description: 基础问题, questions: [ { id: 1, topic_id: 1, content: 什么是JVM }, { id: 2, topic_id: 1, content: 什么是多线程 } ] }, { id: 2, title: 前端开发, description: Vue相关, questions: [ { id: 3, topic_id: 2, content: 什么是响应式 } ] }) this.setData({ list: list }) // wx.request({ // url: http://localhost:8080/api/topic/list, // ⚠️ 改成你的后端地址 // method: GET, // success: (res) { // console.log(res.data) // this.setData({ // list: res.data // }) // }, // fail: (err) { // console.error(请求失败, err) // wx.showToast({ // title: 加载失败, // icon: none // }) // } // }) },效果图麻烦关注一下码文狙击所。