小程序使用模板template

时间:2023-03-10 05:41:36
小程序使用模板template

小程序使用模板template

1.介绍:模板就是代码的高度复用,将在很多页面使用了相同的部分可以使用模板封装

<!-- 在页面组件中使用 -->

<!-- 此时定义了一个模板 -->
<template name="staffName">
<view>
FirstName: {{firstName}}, LastName: {{lastName}}
</view>
</template> <!-- 通过is属性指定使用哪个模板,...staffA是传入的数据 -->
<template is="staffName" data="{{...staffA}}"></template> <!-- 通过外链使用,根目录下新建templates目录,再新建的demo目录,目录下有index.wxml和index.wxss --> <!-- 在页面组件中引入使用 --> <import src="../../templates/demo/index.wxml" /> <template is="last" data="{{msg}}"></template>