美文网首页
小程序开发教程《二》

小程序开发教程《二》

作者: 暖lily | 来源:发表于2019-04-19 14:22 被阅读0次

解析一下页面中所包含的常见模块

(1)头部标题设置
(2)轮播图
(3)tab列表切换显示对应内容
(4)底部tab菜单
(5)请求后台数据
(6)跳转页面

=================现在按步骤举例解析==============

第一:《头部标题设置》在对应页面的js里面设置

wx.setNavigationBarTitle({
title: '首页'
})

第二:《轮播图》

结构swiper.wxml:
<swiper
class='swiper'
indicator-dots="{{indicatorDots}}"
autoplay="{{autoplay}}"
interval="{{interval}}"
duration="{{duration}}" >
<block wx:for="{{imgUrls}}">
<swiper-item>
<image src="{{item}}" class="slide-image" width="750" height="150" />
</swiper-item>
</block>
</swiper>
数据:swiper.js
Page({
data: {
imgUrls: [
'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=750',
'https://images.unsplash.com/photo-1551214012-84f95e060dee?w=750',
'https://images.unsplash.com/photo-1551446591-142875a901a1?w=750'
],
indicatorDots: true,//是否显示小圆点
autoplay: true,//是否自动轮播
interval: 5000,//间隔时间
duration: 1000
}
})

第三:tab列表切换显示对应内容

结构:
<view class="tabNav">
<view wx:for="{{navTab}}" wx:key="index" data-idx="{{index}}" bindtap="currentTab" class="{{currentTab==index ? 'cur' : ''}}"><text id="{{item.id}}">{{item}}</text></view>
</view>
<view class="orderInfo">
<view class="flex-wrp orderInfo-item" wx:for="{{sendList}}" wx:key="index" style="flex-direction:row;" >
<view class='leftImg flex-item'>
<image src="{{item.url}}" class="slide-image" mode='widthFix'/>
</view>
<view class='rightContent flex-item navigation' id="{{item.id}}">
<text class='title'>{{ item.title }}</text>
<text class='describe'>{{ item.productIntroduction }}</text>
<text class='priceRange'>{{ item.author_name }}</text>
</view>
</view>
</view>
数据定义:
Page({
data: {
navTab: ['全部', '佩饰', '生活', '传家', '贺岁'],
currentTab: 0
},
currentTab: function (e) {
if (this.data.currentTab == e.currentTarget.dataset.idx) {
return;
}
this.setData({
currentTab: e.currentTarget.dataset.idx
})
this.getData()
},
getData: function(){//请求后台数据 见 %%%第五:《请求后台数据》%%%
}
})

第四:底部tab菜单

app.json中
"tabBar": {
"backgroundColor": "#fff",
"color": "#A1A1A1",
"selectedColor":"#215094",//选中项的字体颜色
"list": [
{
"pagePath": "pages/shouye/shouye",//对应跳转页面地址
"text": "首页",
"iconPath":"pages/image/home.png",,//对应图标地址
"selectedIconPath":"pages/image/home@2x.png",//对应选中图标地址
},
{
"pagePath": "pages/goodsdetail/goodsdetail",
"text": "商品详情",
"iconPath": "pages/image/user.png",
"selectedIconPath": "pages/image/user@2x.png"
}
]
},

第五:《请求后台数据》

app.js中设置公共域名doubanBase:
App({
globalData: {
userInfo: null,
doubanBase: "http://api.avatardata.cn/"
}
})
在其他页面调用方式:
const app = getApp();
var _url = app.globalData.doubanBase+ '/getList';//请求接口
wx.request({
url: _url,
method: 'post',
header: {
'content-type': 'application/json' // 默认值
},
success(res) {
_this.setData({
sendList: res.data.result.data
})
}
})

第六:跳转页面

结构中:
<view class='navigation'>
<navigator
url="/pages/logs/logs"
hover-class="navigator-hover" >
跳转到新页面
</navigator>
</view>
js中:
wx.navigateTo({
url: '/pages/goodsdetail/goodsdetail'
})

相关文章

  • 小程序云开发教程(初识篇)

    目录一、为什么学小程序云开发二、小程序云开发是什么三、学习准备 系列教程小程序云开发教程(入门篇)小程序云开发教程...

  • 小程序云开发教程(地雷篇,持续更新)

    目录一、代码坑二、IDE缺陷 系列教程小程序云开发教程(初识篇)小程序云开发教程(入门篇) 一、代码坑 二、IDE...

  • 小程序云开发教程(入门篇)

    目录一、了解控制台二、启动云函数能力三、核心概念四、官方文档 系列教程小程序云开发教程(初识篇)小程序云开发教程(...

  • 微信小程序开发系列六:微信框架API的调用

    微信小程序开发系列教程 微信小程序开发系列一:微信小程序的申请和开发环境的搭建 微信小程序开发系列二:微信小程序的...

  • 小程序部署流程

    小程序部署流程: 一、 注册小程序(小程序接入指南) 二、创建小程序项目(简易教程·小程序) 三、部署开发环境(开...

  • 微信小程序开发教程(基础篇)3-app.js 解析

    微信小程序开发教程(基础篇)1-初识微信小程序微信小程序开发教程(基础篇)2-微信小程序结构概览 上一篇教程中写道...

  • 微信小程序从零开始开发

    1、微信小程序开发教程2、小程序官方文档-小程序版

  • 小程序开发教程《二》

    解析一下页面中所包含的常见模块 (1)头部标题设置(2)轮播图(3)tab列表切换显示对应内容(4)底部tab菜单...

  • 小程序官方教程地址总结

    小程序工具下载 开发者工具介绍开发者工具的快捷键 等等 小程序官方教程包括 小程序的基础教程1、起步、2、代码构成...

  • 微信小程序

    微信小程序入门 入门简易教程 小程序开发流程注册小程序->代码开发->提审->上线/审核未通过 开发者工具左侧模拟...

网友评论

      本文标题:小程序开发教程《二》

      本文链接:https://www.haomeiwen.com/subject/anatgqtx.html