小程序内容列表的调用方式
1、导入API文件路径
const api = require('../../utils/api.js'); //路径根据自己的实际情况调整
2、在 index.js 生命周期函数--监听页面加载中编写赋值代码
let scode = 1;
let num = 10;
let order = date;
// 产品栏目列表
api.getList(scode, num, order).then(function (list) {
that.setData({
list: list.data,
})
})
使用微信 wx:for
进行列表渲染,即可使用数组中各项的数据重复渲染该组件
注意:默认数组的当前项的下标变量名默认为 index,数组当前项的变量名默认为 item
<view wx:for="{{list}}" wx:key="this">
<navigator url="../content/content?id={{item.id}}" hover-class="navigator-hover">
<view>{{item.title}}</view>
</navigator>
</view>
{{ list.id }} | 编号 |
{{ list.scode }} | 分类编码 |
{{ list.subscode }} | 副分类编码 |
{{ list.sortname }} | 分类名称 |
{{ list.subsortname }} | 副分类名称 |
{{ list.sortlink }} | 分类链接 |
{{ list.subsortlink }} | 副分类链接 |
{{ list.title }} | 标题 |
{{ list.titlecolor }} | 标题颜色 |
{{ list.subtitle }} | 副标题 |
{{ list.tags }} | 直接输出tags |
{{ list.author }} | 作者 |
{{ list.source }} | 来源 |
{{ list.link }} | 链接 |
{{ list.outlink }} | 外部链接 |
{{ list.date }} | 发布日期 |
{{ list.ico }} | 缩略图,[list:isico]可用于判断,返回1或0 |
{{ list.pics }} | 多图 |
{{ list.content }} | 内容 |
{{ list.enclosure }} | 附件 |
{{ list.enclosuresize }} | 附件大小 |
{{ list.keywords }} | 关键词 |
{{ list.description }} | 描述 |
{{ list.istop }} | 是否置顶 |
{{ list.isrecommend }} | 是否推荐 |
{{ list.isheadline }} | 是否头条 |
{{ list.visits }} | 访问数量 |
{{ list.likes }} | 点赞数量 |
{{ list.oppose }} | 反对数量 |
{{ list.likeslink }} | 点赞链接 |
{{ list.opposelink }} | 反对链接 |
{{ list.ext_*** }} | 调取扩展字段内容 |