请各位按目录检索时注意:
3.1、3.2、3.3…… 等二级目录对应着一个章节。
3.1.1、3.1.2、3.1.3…… 等三级目录将该二级目录这个大章节详细拆分成诸多小坑,方便查看。
本文章原名【微信小程序 100 坑】微信小程序的开发教程,或许写出来是非常受欢迎的。
本组件目前已有 5 个坑,有兴趣的小伙伴可以详看。
demo.wxml<swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}"> <block wx:for="{{imgUrls}}"> <swiper-item> <image src="{{item}}" class="slide-image" width="355" height="150"/> </swiper-item> </block></swiper><button bindtap="changeIndicatorDots"> indicator-dots </button><button bindtap="changeAutoplay"> autoplay </button><slider bindchange="intervalChange" show-value min="500" max="2000"/> interval<slider bindchange="durationChange" show-value min="1000" max="10000"/> duration复制代码
demo.jsPage({ data: { imgUrls: [ 'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg', 'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg', 'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg' ], indicatorDots: false, autoplay: false, interval: 5000, duration: 1000 }, changeIndicatorDots: function(e) { this.setData({ indicatorDots: !this.data.indicatorDots }) }, changeAutoplay: function(e) { this.setData({ autoplay: !this.data.autoplay }) }, intervalChange: function(e) { this.setData({ interval: e.detail.value }) }, durationChange: function(e) { this.setData({ duration: e.detail.value }) }})复制代码
index.wxml<view class="carousel"> <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" indicator-color="#707071" indicator-active-color="#fff" circular="true"> <!-- wx:key : 提高列表渲染效率 --> <block wx:for="{{imgUrls}}" wx:key="{{item.index}}"> <swiper-item> <navigator url="{{item.link}}" hover-class="navigator-hover"> <image src="{{item.url}}" class="slide-image" /> </navigator> </swiper-item> </block> </swiper></view>复制代码
index.wxss.carousel .slide-image { width: 100%; height: 420rpx;}复制代码
index.jsPage({ data: { imgUrls: [ { link: '../index/index', url: 'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg', }, { link: '../demo/demo', url: 'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg', }, { link: '../logs/logs', url: 'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg' } ], indicatorDots: true, autoplay: true, interval: 5000, duration: 1000 }})复制代码
本组件目前已有 3 个坑,有兴趣的小伙伴可以详看。tabBar :底部菜单栏,需要在 app.json 中设置。使用方法:见下文。
app.json"tabBar": { "list": [{ "pagePath": "pages/index/index", "text": "首页", "iconPath": "./public/index_tabBar1_nor.png", "selectedIconPath": "./public/index_tabBar1.png" }, { "pagePath": "pages/demo/demo", "text": "发现", "iconPath": "./public/index_tabBar2_nor.png", "selectedIconPath": "./public/index_tabBar2.png" }, { "pagePath": "pages/logs/logs", "text": "我的", "iconPath": "./public/index_tabBar3_nor.png", "selectedIconPath": "./public/index_tabBar3.png" }] }复制代码
demo.wxml<view> <button bindtap="linkTo">Hello</button></view>复制代码
demo.jslinkTo: function () { wx.switchTab({ url: '../index/index' });},复制代码
注:图片宽高均为 54rpx
*.wxml<view class="nav"> <view class="nav-home" bindtap="goHome"> <image src="../../public/index_productDetail_icon_home.png"></image> <text>首页</text> </view> <view class="nav-service"> <image src="../../public/index_productDetail_icon_service.png"></image> <text>在线咨询</text> </view> <view class="nav-phone" bindtap="callWaiter"> <image src="../../public/index_productDetail_icon_phone.png"></image> <text>电话咨询</text> </view> <navigator url="../indexPurchaseProduct/indexPurchaseProduct"> <view class="nav-buy"> <text>立即订购</text> </view> </navigator></view>复制代码
*.wxss.nav { display: flex; justify-content: space-around; font-size: 20rpx; border: 1px solid #ccc; position: fixed; bottom: 0; background: #fff;}.nav view { display: flex; flex-direction: column; align-items: center;}.nav image { width: 54rpx; height: 54rpx;}.nav text { margin-top: 7rpx;}.nav-home { border-right: 1px solid #ccc; width: 130rpx; padding-top: 5rpx;}.nav-service { border-right: 1px solid #ccc; width: 130rpx; padding-top: 5rpx;}.nav-phone { width: 130rpx; padding-top: 5rpx;}.nav-buy { background: #eb333e; color: #fff; width: 360rpx; height: 98rpx; line-height: 80rpx; font-size: 34rpx;}复制代码
*.jscallWaiter: function(res) { wx.makePhoneCall({ phoneNumber: '13264862250', success: function(res) { console.log("拨打成功"); console.log(res); }, fail: function(res) { console.log("拨打失败"); console.log(res); }, complete: function(res) { console.log("拨打完成"); console.log(res); } })},goHome: function() { wx.switchTab({ url: '../index/index' })},复制代码
navBar.wxml<!-- 底部导航条 --><view class="navBar"> <view class="navBar-home" bindtap='goHome'> <image wx:if="{{homeActive}}" src="../../public/index_tabBar1.png"></image> <image wx:if="{{!homeActive}}" src="../../public/index_tabBar1_nor.png"></image> <text>首页</text> </view> <view class="navBar-explore" bindtap='goExplore'> <image wx:if="{{exploreActive}}" src="../../public/index_tabBar2.png"></image> <image wx:if="{{!exploreActive}}" src="../../public/index_tabBar2_nor.png"></image> <text>发现</text> </view> <view class="navBar-user" bindtap='goUser'> <image wx:if="{{userActive}}" src="../../public/index_tabBar3.png"></image> <image wx:if="{{!userActive}}" src="../../public/index_tabBar3_nor.png"></image> <text>我的</text> </view></view>复制代码
navBar.wxss/* 底部导航条 */.navBar { width: 100%; padding: 18rpx 0; border-top: 1rpx solid #cccccc; display: flex; justify-content: space-around; position: fixed; bottom: 0; background: #fff;}.navBar image { width: 55rpx; height: 55rpx;}.navBar view { display: flex; flex-direction: column; align-items: center; font-size: 20rpx; color: #999999;}.navBar-user text { color: #d0a763;}复制代码
navBar.js// pages/componentNavBar/navBar.jsComponent({ /** * 组件的属性列表 */ properties: { homeActive: { type: Boolean, value: false }, exploreActive: { type: Boolean, value: false }, userActive: { type: Boolean, value: false } }, /** * 组件的初始数据 */ data: { }, /** * 组件的方法列表 */ methods: { // 返回首页 goHome: function (e) { wx.switchTab({ url: '../index/index', }) }, // 返回发现页 goExplore: function (e) { wx.switchTab({ url: '../explore/explore', }) }, // 返回我的页面 goUser: function (e) { wx.switchTab({ url: '../user/user', }) }, showCode: function(e) { console.log(e); let that = this; console.log(that.data); } }})复制代码
navBar.json{ "component": true, "usingComponents": {}}复制代码
*.wxml<view> <navBar userActive="{{userActive}}"></navBar></view>复制代码
*.json{ "usingComponents": { "navBar": "../componentNavBar/navBar" }}复制代码
*.jsdata: { userActive: true},复制代码
本节目前已有1个坑,有兴趣的小伙伴可以详看。在微信中,它自带了一套属于自己的单位:rpx , rpx 不同于之前我们认识的 px 、 rem 、 em ,如果你的设计稿是 750 px 的,那么很容易的, 1px = 1rpx ,但是,如果设计稿不是 750 px ,那么将造成一个 bug ,至于这个 bug 如何解决……
本节目前已有 2 个坑,有兴趣的小伙伴可以详看。
本节目前已有 2 个坑,有兴趣的小伙伴可以详看。[url=]3.5.1 概念混淆:组件 VS API[/url] 返回目录
本节目前已有 3 个坑,有兴趣的小伙伴可以详看。Flex布局又称弹性布局,在小程序开发中比较适用。但是由于 jsliang 之前没怎么用过 Flex 布局,所以在这里咱们特意去踩下坑,充实下自己。【小程序开发之页面布局】【阮一峰-Flex 布局教程】
*.wxml<view class="top-recommended-headlines"> <view class="top-recommended-headlines-left"> <text>热门推荐</text> </view> <view> <image src="../../public/index_top_recommended_headlines.png"></image> </view> <view class="top-recommended-headlines-right"> <navigator url="../indexProduct/indexProduct">查看全部 ></navigator> </view></view>复制代码
*.wxss.top-recommended-headlines { display: flex; align-items: flex-end; height: 31rpx; line-height: 31rpx; margin-bottom: 10rpx;}.top-recommended-headlines-left text { font-size: 32rpx; font-weight: bold;}.top-recommended-headlines image { width: 366rpx; height: 31rpx; margin-left: 10rpx;}.top-recommended-headlines-right navigator { font-size: 26rpx; color: #a9a9a9; margin-left: 50rpx;}复制代码
*.wxml<view class="weui-tab__content-item3" wx:for="{{tabs3Content}}" wx:key="{{item.index}}"> <navigator url="../indexProductArticle/indexProductArticle"> <view class="weui-tab__content-item3-question"> <image src="../../public/index_productDetail_icon_question.png"></image> <text>{{item.title}}</text> </view> <view class="weui-tab__content-item3-answer"> <image src="../../public/index_productDetail_icon_answer.png"></image> <text>{{item.content}}</text> </view> <view class="weui-tab__content-item3-detail"> <text class="weui-tab__content-item3-detail-datatime">{{item.datatime}}</text> <text class="weui-tab__content-item3-detail-reader">{{item.reader}}阅读</text> <text class="weui-tab__content-item3-detail-label">#{{item.label}}#</text> </view> </navigator> <view class="weui-tab__content-item3-gap"> <image src="../../public/index_productDetail_gap.png"></image> </view></view>复制代码
*.wxss.weui-tab__content-item3 { padding-left: 30rpx; padding-right: 30rpx; margin-top: -10rpx; margin-bottom: 10rpx;}.weui-tab__content-item3:first-child { padding: 40rpx 30rpx 0;}.weui-tab__content-item3-question image { width: 30rpx; height: 30rpx;}.weui-tab__content-item3-question text { font-size: 30rpx; line-height: 46rpx; font-weight: bold; color: #333; margin-left: 10rpx;}.weui-tab__content-item3-answer image { width: 30rpx; height: 30rpx;}.weui-tab__content-item3-answer text { font-size: 26rpx; line-height: 42rpx; color: #a9a9a9; margin-left: 10rpx;}.weui-tab__content-item3-detail { display: flex; justify-content: space-between; font-size: 26rpx; color: #a9a9a9;}.weui-tab__content-item3-detail-label { color: #d0a763;}.weui-tab__content-item3-gap image { width: 100%; height: 30rpx;}复制代码
*.jstabs3Content: [ { title: '员工发明创造是否属于职务发明的认证标准?', content: '随着企业对知识产权在企业发展中核心竞争力的认识力提高,企业保护自身知识产权的意识不断增强,使其技术得......', datatime: '2018-03-05', reader: '2081', label: '知识产权' }]复制代码
本节目前已有 1 个坑,有兴趣的小伙伴可以详看。在小程序中,如果你使用 wxss,你是可以发现有 background-image 的提示的。但是,如果你设置它的背景图是本地图片,你会发现,它是不生效的。
本节目前已有 1 个坑,有兴趣的小伙伴可以详看。两者的区别是,<view> 是一个组件,会在页面上做渲染;<block> 不是一个组件,它仅仅是一个包装元素,只接受控制属性,不会在页面中做任何渲染。
本节目前已有 2 个坑,有兴趣的小伙伴可以详看。
*.wxml<view class="search"> <input class="search-product-input" bindinput="bindKeyInput" auto-focus maxlength='10'></input> <label class="search-placeholder"> <image class="search-placeholder-icon" src="../../public/index_indexProduct_icon_search.png"></image> <text class="search-placeholder-text">搜索产品</text> </label> <view></view></view>复制代码
*.wxss.search { height: 100rpx; display: flex; flex-direction: column; justify-content: space-between; align-items: center; position: relative;}.search-product-input { background: #f5f5f5; width: 650rpx; height: 65rpx; border-radius: 30rpx; font-size: 30rpx; padding-left: 20rpx;}.search-placeholder { font-size: 26rpx; text-align: center; margin-top: -65rpx; z-index: 2;}.search-placeholder-icon { width: 24rpx; height: 24rpx;}.search-placeholder-text { margin-left: 10rpx;}复制代码
*.wxml<!-- 搜索框 --><view class="search"> <view class="weui-search-bar"> <view class="weui-search-bar__form {{inputShowed ? 'form-border' : ''}}"> <view class="weui-search-bar__box"> <icon class="weui-icon-search_in-box" type="search" size="14"></icon> <input type="text" class="weui-search-bar__input" placeholder="搜索" value="{{inputVal}}" focus="{{inputShowed}}" bindinput="inputTyping" /> <view class="weui-icon-clear" wx:if="{{inputVal.length > 0}}" bindtap="clearInput"> <icon type="clear" size="14"></icon> </view> </view> <label class="weui-search-bar__label" hidden="{{inputShowed}}" bindtap="showInput"> <icon class="weui-icon-search" type="search" size="14"></icon> <view class="weui-search-bar__text">搜索</view> </label> </view> <view wx:if="{{inputVal.length <= 0}}" class="weui-search-bar__cancel-btn" hidden="{{!inputShowed}}" bindtap="hideInput">取消</view> <view wx:if="{{inputVal.length > 0}}" class="weui-search-bar__submit-btn" hidden="{{!inputShowed}}" bindtap="searchInput">搜索</view> </view></view>复制代码
*.jsPage({ data: { inputShowed: false, inputVal: "" }, showInput: function () { this.setData({ inputShowed: true }); }, hideInput: function () { this.setData({ inputVal: "", inputShowed: false }); }, clearInput: function () { this.setData({ inputVal: "" }); }, inputTyping: function (e) { this.setData({ inputVal: e.detail.value }); }})复制代码
*.wxss.search { height: 100rpx; padding: 18rpx 30rpx;}.weui-search-bar { padding: 0; background-color: #fff; border-top: none; border-bottom: none; height: 64rpx;}.weui-search-bar__form { border: none;}.form-border { border: 1rpx solid #f5f5f5; background: #f5f5f5;}.weui-search-bar__label { background: #f5f5f5; border-radius: 30rpx;}.weui-search-bar__cancel-btn { font-size: 26rpx; background: rgb(8, 202, 186); color: #fff; padding: 2rpx 20rpx 0 20rpx; border-radius: 10rpx;}.weui-search-bar__submit-btn { font-size: 26rpx; background: rgb(8, 200, 248); color: #fff; padding: 10rpx 20rpx 0 20rpx; border-radius: 10rpx;}复制代码
本节目前已有 1 个坑,有兴趣的小伙伴可以详看。官方文档:地址
本节目前已有 1 个坑,有兴趣的小伙伴可以详看。熟知盒模型的小伙伴应该知道,盒模型有两种计算方式:
本节目前已有 6 个坑,有兴趣的小伙伴可以详看。
app.wxss/* 引用WeUI */@import 'weui.wxss';复制代码
*.wxml<view class="tab"> <view class="weui-tab"> <view class="weui-navbar"> <block wx:for="{{tabs}}" wx:key="*this"> <view id="{{index}}" class="weui-navbar__item {{activeIndex == index ? 'weui-bar__item_on' : ''}}" bindtap="tabClick"> <view class="weui-navbar__title">{{item}}</view> </view> </block> <view class="weui-navbar__slider" style="left: {{sliderLeft}}px; transform: translateX({{sliderOffset}}px); -webkit-transform: translateX({{sliderOffset}}px);"></view> </view> <view class="weui-tab__panel"> <!-- 全部 --> <view class="weui-tab__content" hidden="{{activeIndex != 0}}"> <view class="weui-tab__content-item1"> <text>全部</text> </view> </view> <!-- 已付款 --> <view class="weui-tab__content" hidden="{{activeIndex != 1}}"> <view class="weui-tab__content-item2"> <text>已付款</text> </view> </view> <!-- 待付款 --> <view class="weui-tab__content" hidden="{{activeIndex != 2}}"> <view class="weui-tab__content-item3"> <text>待付款</text> </view> </view> </view> </view></view>复制代码
*.wxss.tab { font-size: 26rpx;}.tab image { width: 173rpx; height: 29rpx;}.weui-navbar { border-top: 1rpx solid #efefef; border-bottom: 1rpx solid #efefef;}.weui-navbar__slider { background: #d0a763; width: 4em;}.weui-navbar__item.weui-bar__item_on { color: #d0a763;}.weui-tab__content { margin-bottom: 100rpx;}复制代码
*.jsvar sliderWidth = 52; // 需要设置slider的宽度,用于计算中间位置Page({ /** * 页面的初始数据 */ data: { // 选项卡导航 tabs: ["全部", "已付款", "待付款"], activeIndex: 1, sliderOffset: 0, sliderLeft: 0, }, // 选项卡切换 tabClick: function (e) { this.setData({ sliderOffset: e.currentTarget.offsetLeft, activeIndex: e.currentTarget.id }); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // 计算搜索框活跃条 var that = this; wx.getSystemInfo({ success: function (res) { that.setData({ sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2, sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex }); } }); }})复制代码
*.wxml<view> <view class="weui-tab__nav"> <text wx:for="{{tabs2Nav}}" wx:key="item.index" class="{{item.state == 1 ? 'weui-tab__nav-active' : ''}}" bindtap="tabs2NavClick" data-labelId="{{item.id}}">{{item.label}}</text> </view> <view class="weui-tab__content-item2" wx:for="{{tabs2Content}}" wx:key="{{item.index}}"> <view class="weui-tab__content-item-descritpion"> <view class="{{item.type == 1 ? 'weui-tab__content-item-icon-type' : 'hide'}}"> <image src="../../public/index_productDetail_icon_word.png"></image> </view> <view class="{{item.type == 2 ? 'weui-tab__content-item-icon-type' : 'hide'}}"> <image src="../../public/index_productDetail_icon_excel.png"></image> </view> <view class="{{item.type == 3 ? 'weui-tab__content-item-icon-type' : 'hide'}}"> <image src="../../public/index_productDetail_icon_ppt.png"></image> </view> <view class="{{item.type == 4 ? 'weui-tab__content-item-icon-type' : 'hide'}}"> <image src="../../public/index_productDetail_icon_pdf.png"></image> </view> <view class="weui-tab__content-item-descritpion-content"> <text class="weui-tab__content-item-descritpion-content-title">{{item.title}}</text> <view class="weui-tab__content-item-descritpion-content-datatime"> <text class="weui-tab__content-item-descritpion-content-datatime1">发布时间:{{item.datatime}}</text> <text class="{{item.effectiveTime ? 'weui-tab__content-item-descritpion-content-datatime2' : 'hide'}}">生效时间:{{item.effectiveTime}}</text> </view> </view> </view> <view class="weui-tab__content-item-download-state" bindtap='downloadFile' data-url="{{item.url}}"> <image src="../../public/index_productDetail_icon_undown.png"></image> </view> </view></view>复制代码
*.wxss.weui-tab__nav { background: #f5f5f5; border: 1rpx 0rpx solid #e6e6e6; height: 90rpx; padding: 17rpx 41rpx; display: flex; justify-content: space-between;}.weui-tab__nav text { border-radius: 56rpx; height: 56rpx; line-height: 56rpx; padding: 15rpx 23rpx; font-size: 26rpx; font-weight: bold;}.weui-tab__nav-active { color: #fefefe; background: #d0a763;}.weui-tab__content-item2 { display: flex; justify-content: space-between; padding: 25rpx 30rpx;}.weui-tab__content-item-descritpion { display: flex; justify-content: space-between;}.weui-tab__content-item-descritpion image { width: 60rpx; height: 70rpx;}.hide { display: none;}.weui-tab__content-item-descritpion-content { margin-left: 26rpx;}.weui-tab__content-item-descritpion-content-title { font-size: 28rpx; font-weight: bold; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical;}.weui-tab__content-item-descritpion-content-datatime { font-size: 22rpx; color: #bbb;}.weui-tab__content-item-descritpion-content-datatime1 { margin-right: 35rpx;}.weui-tab__content-item-download-state image { width: 64rpx; height: 64rpx;}复制代码
*.jsdata: { tabs2Nav: [ { id: '1', label: '法律大全', state: 1 }, { id: '2', label: '合同模板', state: 0 }, { id: '3', label: '民事', state: 0 }, { id: '4', label: '行政', state: 0 }, { id: '5', label: '执行', state: 0 } ], tabs2Content: [ { title: '中华人名共和国民用航空法(2015年...).doc', url: 'https://wxmcard.imusic.cn/testfordocdownload.doc', datatime: '2018-01-26', effectiveTime: '2018-01-26', type: '1' }, { title: '原生申诉表格.xls', url: 'https://wxmcard.imusic.cn/testfordocdownload.doc', datatime: '2018-01-26', type: '2' }, { title: '法律常识大汇集及范例.ppt', url: 'https://wxmcard.imusic.cn/testforpptdownload.pptx', datatime: '2018-01-26', effectiveTime: '2018-01-26', type: '3' }, { title: '事业单位法律基础知识总结.pdf', url: 'https://wxmcard.imusic.cn/testforpdfdownload.pdf', datatime: '2018-01-26', effectiveTime: '2018-01-26', type: '4' } ], // 选项卡第二屏分组 tabs2Content1: [ { title: '中华人名共和国民用航空法(2015年...).doc', datatime: '2018-01-26', effectiveTime: '2018-01-26', type: '1' }, { title: '原生申诉表格.xls', datatime: '2018-01-26', type: '2' }, { title: '法律常识大汇集及范例.ppt', datatime: '2018-01-26', effectiveTime: '2018-01-26', type: '3' }, { title: '事业单位法律基础知识总结.pdf', datatime: '2018-01-26', effectiveTime: '2018-01-26', type: '4' } ], tabs2Content2: [ { title: '合同模板.doc', datatime: '2018-01-26', effectiveTime: '2018-01-26', type: '1' } ], tabs2Content3: [ { title: '民事合同模板.doc', datatime: '2018-01-26', effectiveTime: '2018-01-26', type: '1' } ], tabs2Content4: [ { title: '行政合同模板.doc', datatime: '2018-01-26', effectiveTime: '2018-01-26', type: '1' } ], tabs2Content5: [ { title: '执行合同模板.doc', datatime: '2018-01-26', effectiveTime: '2018-01-26', type: '1' } ]},// 选项卡2切换tabs2NavClick: function(e) { var that = this; console.log("完整的数据是:"); console.log(that.data.tabs2Nav); console.log("点击的标签是:"); console.log(e.currentTarget.dataset.labelid); var newTabs2Content; console.log("正在经历的标签是:"); for(var i=0; i<that.data.tabs2Nav.length; i++) { console.log(that.data.tabs2Nav.id); that.data.tabs2Nav.state = 0; if (that.data.tabs2Nav.id == e.currentTarget.dataset.labelid) { that.data.tabs2Nav.state = 1; console.log("将改变的标签是:"); console.log(that.data.tabs2Nav); // 改变内容 var changeContentName = "tabs2Content" + (i + 1); if (changeContentName == "tabs2Content1") { console.log(that.data.tabs2Content1); newTabs2Content = that.data.tabs2Content1; } else if (changeContentName == "tabs2Content2") { newTabs2Content = that.data.tabs2Content2; } else if (changeContentName == "tabs2Content3") { newTabs2Content = that.data.tabs2Content3; } else if (changeContentName == "tabs2Content4") { newTabs2Content = that.data.tabs2Content4; } else { newTabs2Content = that.data.tabs2Content5; } console.log("希望转换内容到:"); console.log(changeContentName); } } this.setData({ tabs2Nav: that.data.tabs2Nav, tabs2Content: newTabs2Content })},复制代码
本节目前已有 2 个坑,有兴趣的小伙伴可以详看。
*.wxml<text class="article-message-board-head-addMessage" bindtap="modalinput">写留言</text>复制代码
*.jsPage({ data: { // 弹窗 hiddenmodalput: true, //可以通过hidden是否掩藏弹出框的属性,来指定那个弹出框 }, //点击按钮指定的hiddenmodalput弹出框 modalinput: function () { this.setData({ hiddenmodalput: !this.data.hiddenmodalput }) }, //取消按钮 cancel: function () { this.setData({ hiddenmodalput: true }); }, //确认 confirm: function () { wx.showToast({ title: '留言成功!', }) this.setData({ hiddenmodalput: true }) }})复制代码
本节目前已有 5 个坑,有兴趣的小伙伴可以详看。
本节目前已有 1 个坑,有兴趣的小伙伴可以详看。在小程序中,它有一些自定义的方法,例如 open-type ,是需要 <button> 来承接的。
本节目前已有 1 个坑,有兴趣的小伙伴可以详看。就像上一章所说的,有时候,迫不得已,我们必须在 <button> 中内嵌个 <image> 或者 <text> 之类的,那么,一般怎么做呢?
*.wxml<button open-type='share'> <image src="../../public/explore_activityDetail_icon_share.png"></image></button>复制代码
*.wxss.activity-user-action button { width: 42rpx; height: 80rpx; margin: 0; padding: 0; margin-top: -21rpx; background: #fff;}.activity-user-action button::after { border: none;}.activity-user-action image:last-child { width: 42rpx; height: 40rpx;}复制代码
本节目前已有 2 个坑,有兴趣的小伙伴可以详看。在浏览器中,有 F5 刷新,有鼠标滚轮滑动加载。
本节目前已有 1 个坑,有兴趣的小伙伴可以详看。<input class="phone-number"></input>
*.wxml<input maxlength='11' placeholder='请输入手机号码' placeholder-class="phone-number" name="phoneNumber" bindinput='phoneNumberInput'></input><button class="get-phone-number" bindtap="getPhoneNumber">获取验证码</button>复制代码
*.jsPage({ data: { // 输入的手机号码 phonenumber: '', }, // 获取手机号码 phoneNumberInput: function(e) { this.setData({ phonenumber: e.detail.value }) }, // 点击获取验证码 getPhoneNumber: function (e) { var phoneNumber = this.data.phonenumber console.log(phoneNumber); }})复制代码
本节目前已有 2 个坑,有兴趣的小伙伴可以详看。[url=]3.19.1 小程序执行顺序[/url] 返回目录
index.jsonLoad: function (options) { if (!wx.getStorageSync('isLogin')) { wx.redirectTo({ url: '../login/login', }) }}复制代码
login.jsloginSubmit: function(e) { wx.setStorageSync('isLogin', true);}复制代码
本节目前已有 1 个坑,有兴趣的小伙伴可以详看。在 Ansen江 的推荐下,参照 Ansen江 的 api.js,对我这边的小程序接口 request 进行了 promise 封装,并做了 api.js 的分离。
api.js/* * @Author: jsliang * @Date: 2018-10-11 09:11:26 * @LastEditors: jsliang * @LastEditTime: 2018-10-11 09:11:29 * @Description: 接口文件 */// 引入请求头文件import header from './header.js';// 加载中const Loading = { show() { wx.showLoading({ title: '加载中' }); }, hide() { wx.hideLoading() }};// 加载中白名单const loadingWhite = [ 'index/index']// 将请求进行 Promise 封装const fetch = ({url, data, header}) => { // 白名单地址会显示加载中状态 if(loadingWhite.includes(url)) { Loading.show(); } // 打印接口请求的信息 console.log(`【step1】API接口:${url}`); console.log("【step2】header请求头:"); console.log(header); console.log("【step3】data传参:"); console.log(data); // 返回 Promise return new Promise((resolve, reject) => { wx.request({ url: getApp().globalData.api + url, header: header, data: data, success: res => { Loading.hide(); // 成功时的处理 if (res.data.code == 0) { console.log("【step4】请求成功:"); console.log(res.data); return resolve(res.data); } else { wx.showModal({ title: '请求失败', content: res.data.message, showCancel: false }); } }, fail: err => { Loading.hide(); // 失败时的处理 console.log(err); return reject(err); } }) })}/** * code 换取 openId * @data { * jsCode - wx.login() 返回的 code * } */export const wxLogin = data => { return fetch({ url: "tbcUser/getWechatOpenId", header: header.newHeader(), data: data })}复制代码
login.jsimport { wxLogin} from "../../utils/api.js"// 登录wx.login({ success: res => { // 发送 code ,获取 openId console.log("\n【API:获取 openId】"); wxLogin({ jsCode: res.code }).then( res => { console.log("【step5】返回成功处理:"); console.log(res); }, err => { console.log("【step5】返回失败处理:"); console.log(err); } ) }})复制代码
本节目前已有 1 个坑,有兴趣的小伙伴可以详看。在页面布局中,我们经常使用列表展示,然后在列表展示上,有时候该列表的最后一条数据下面是没有下划线或者虚线的。
*.wxml<view class="content"> <view wx:for="{{topRecommended}}" wx:key="{{item.recommendId}}" wx:for-index="index"> <navigator url="../indexProduct/indexProduct"> <view class="content-item"> <image src="{{item.coverImage}}"></image> <view class="content-item-text"> <text class="content-item-text-title">{{item.recommendTitle}}</text> <text class="content-item-text-content">{{item.recommendDescription}}</text> <view class="content-item-text-row"> <text class="content-item-text-user">{{item.userCount}}人在用</text> <text class="content-item-text-price">¥{{item.productPrice}}</text> </view> </view> </view> </navigator> <view class="{{(index+1) == topRecommended.length ? 'content-item-gap-hide' : 'content-item-gap'}}"> <image src="../../public/index_top_recommended_content_item_gap.png"></image> </view> </view></view>复制代码
注:小伙伴们提出的 bug,如果包含详细的问题描述和解决方案,我会统计进该文章的 bug 清单。
本组件目前已有 ? 个坑,有经验的小伙伴可以进行补充。
奈斯
| 欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |