1. 程式人生 > >微信小程序制作-隨筆3

微信小程序制作-隨筆3

port XML 需要 for 開頭 模板 src data imp

template模板的應用

  步驟: 1、建template文件夾,在裏面建每一個模板文件夾。 2、寫模板的wxml,wxss,確定模板的樣式。註意:在模板的第一個塊元素要起name屬性。 3、引入模板:1.在需要引入的位置寫<template>標簽,具體如下:
 <template is="shop" wx:for="{{shoplst}}"wx:key="{{item}}"data="{{...item}}" />
is:所找的模板名字。wx:for:循環的js裏的數據。data:...item的寫法是為了方便模板調用數據直接用數組裏的鍵。 註意:需要在開頭引入模板,如:
<import src="
./templates/shop/shop.wxml" />
4、引入css 在母版的css樣式中引入模板的css,如:
@import "./templates/shop/shop.wxss";

微信小程序制作-隨筆3