微信小程式模板中使用迴圈

2021-09-08 13:59:58 字數 1415 閱讀 3926

原創文章

本篇介紹如何在模板裡使用迴圈。

方法一:

template.wxml,該檔案內容為:

<

template

name

="msgitem1"

>

<

block

wx:for

="}"

wx:for-item

="item"

wx:key

="pro"

>

<

view

>

<

text

> }: }

text

>

<

text

> time: }

text

>

view

>

block

>

template

>

方法二:使用模板:

template.wxml,該檔案內容為:

<

template

name

="msgitem"

>

<

view

>

<

text

> }: }

text

>

<

text

> time: }

text

>

view

>

template

>

<

template

name

="msgitem1"

>

<

block

wx:for

="}"

wx:for-item

="item"

wx:key

="pro"

>

<

template

is="msgitem"

data

="}"

/>

block

>

template

>

index.js的內容為:

page(, , ,]

},})

我們在index.wxml裡的內容為:

<

import

src="../template/template.wxml"

/>

<

template

is="msgitem1"

data

="}"

/>

這裡不需要使用擴充套件運算子展開product1。

微信小程式模板中使用迴圈

本篇介紹如何在模板裡使用迴圈。方法一 template.wxml,該檔案內容為 name msgitem1 wx for wx for item item wx key pro text time text view block template 方法二 使用模板 template.wxml,該檔案...

微信小程式中使用watch

設定 setwatcher page let lastkey key key.length 1 假設key my.name 此時nowdata data my data.my,lastkey name let watchfun watch v handler watch v 相容帶handler和不...

微信小程式(模板)

1.模板 wxml提供模板 template 可以在模板中定義 片段,然後在不同的地方呼叫。定義模板 使用name屬性,作為模板的名字。然後在內定義 片段,如 name postitem class post container class post author date class post a...