首先,在根目录下创建template文件夹,并在其中创建component(包含js,wxml,wxss和json)

然后在wxml在wxml内的HTML标签外套上 template标签 并设置 name属性

在写入css样式,此处不再放图
最后,在需要使用template的页面,先使用import标签导入模板(注意import标签的末尾不要忘记 "/")
再在wxml中只用模板,并在is属性填入对应模板的name。
template内实现数据绑定时, 使用{{...item}}es6展开符,就不用在绑定数据时再加入item

Ps:template模板不支持直接使用wx-for循环,需要在外层套一个view标签,再使用block标签实现wx:for

网友评论