這里的微信小程序動態加載是以按鈕為例,主頁面點擊不同的按鈕進入不同的子頁面中,根據主頁面的title來動態加載子頁面按鈕的數量以及值。
效果圖:
wxml文件(注意wx:key="item"要寫,不然它會有警告):
<!--pages/plan/plans/plans.wxml--><view class="className" style="background-color: rgb(225, 218, 211); height:{{className_height}}px" wx:for="{{array}}" wx:key="item"> <button class="items" id="{{stv.id[index]}}">{{item.name}}</button></view>
這里起關鍵作用的是wx:for,這里是循環。
wxss文件:
/* pages/plan/plans/plans.wxss */.items { background-color: rosybrown; width:60%; }
js文件:
// pages/plan/hot/hot.js Page({ data: { }, onLoad: function (options) { var that = this; var arr = new Array(); if (options.title == "熱門") { var location1 = { name: "1" }; var location2 = { name: "2" }; var location3 = { name: "3" }; var location4 = { name: "4" }; var location5 = { name: "5" }; var location6 = { name: "6" }; arr.push(location1); arr.push(location2); arr.push(location3); arr.push(location4); arr.push(location5); arr.push(location6); console.log("OK"); } else { var location1 = { name: "2" }; var location2 = { name: "4" }; var location3 = { name: "5" }; arr.push(location1); arr.push(location2); arr.push(location3); } wx.setNavigationBarTitle({title:'創建新計劃--'+options.title}); wx.getSystemInfo({ success: function (res) { that.setData({ //view className_height: res.windowHeight / arr.length, //btn array: arr, }) } }) },})
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答