WeChat小程序学习心得——模板使用

来源:互联网 发布:数据库黑客大曝光 编辑:程序博客网 时间:2024/06/05 20:08

在footer.wxml下编写两个模板

<template name="footer1">这是底部1 - {{text}}</template><template name="footer2">这是底部2 - {{text}}</template>

导入模板

在需要导入footer.wxml中两个模板的wxml界面,使用import导入footer.wxml文件

<import src="../templates/footer"/>
然后选取指定的模板,并可用data=""对模板中的数据进行动态修改

<template is="footer1" data="{{text:'导入设置的内容'}}"/>
本例使用footer1模板,并对其text赋值

值得注意的是:如果在footer.wxml导入有另一模板temDemo.wxml,则其它页面(如 index.wxml)在导入footer.wxml时,无法将temDemo.wxml一并导入

具体代码可见我上传的资源 WeChat小程序数据渲染和模板使用
原创粉丝点击