小程序中模板的使用如下:
1.一般定义模板需要新建一个文件夹,一般命名为template文件
2.wxml代码如下:
<template name="loading">
<view class="loadingData">
<image src="/images/menu/loadingData.gif"></image>
<text>数据加载中</text>
</view>
</template>
3.需要在app.wxss文件中引入模板的css样式以下代码仅供参考
@import "/pages/template/loading/loading.wxss";
4.需要使用模板的页面引入模板,代码如下:
<import src="/pages/template/loading/loading.wxml" />
<view hidden="{{loading}}">
</view>
<view hidden="{{!loading}}" style="height: 100%">
<template is="loading" />//和模板中name属性值一样
</view>
5.最后需要在data中给个默认值true,调完接口赋值为false