{{}}
wx:for
,同时设置好wx:key
。否则,编辑器老是有红色警告。wx:if
,wx:else
or wx:elif
import
= 引入模板文件,include
= 复制文件源码, @import
引入样式文件能够抽象,并重复使用的就能够作成组件。
好比:分享组件、Tab组件、Pannel组件等等。php
***组件使用,支持服务器下发分享按钮文本和分享内容*** <comp-share text="{{shareconfig.ShareButtonText}}"></comp-share>
***share.js*** Component({ /** * 组件的属性列表 */ properties: { text: { type: String, value: '分享给好友' } }, /** * 组件的初始数据 */ data: { }, /** * 组件的方法列表 */ methods: { onTapButton (e) { this.triggerEvent('tapbutton', {e}) } } })
***share.wxml*** <view class="flex items-center"> <button open-type="share" class="button">{{text}}</button> </view>
***share.wxss*** @import '../../static/wxss/common.wxss'; .button { background: linear-gradient(#AEAEF9, #9ED1FA); box-shadow: 1rpx 1rpx 1rpx 1rpx #C28230; position: fixed; align-content: center; bottom: 30rpx; width: 30%; height: 60rpx; border-radius: 30rpx; font-size: 30rpx; margin: 0 35%; color: white; line-height: 60rpx; }
效果图
![]()
***使用*** // 获取金币收入列表 var Request = require('request.js') function getIncome(page = 1, success) { var url = Common.API + '/User/MyIncome/' + page Request.Get(url, success) }
***request.js*** function Get(url, success, err = errhandle, header = HEADER) { ShowLoading() return wx.request({ url: url, success: function (res) { // console.log('geturl', res) wx.hideLoading() if (res.statusCode != 200) { err(res.data) return } success(res.data.data) }, header: header }) } function Post(url, data, success, err = errhandle, header = HEADER) { wx.hideLoading() return wx.request({ url: url, data: data, method: 'POST', success: function (res) { wx.hideLoading() if (res.statusCode != 200) { err(res.data) return } success(res.data.data) }, header: header }) } module.exports = { Get: Get, Post: Post }
见本文小程序
在小程序段必须使用form,获取到form_id,并和其余数据一块儿传给服务器。后端
在小程序后台申请模板消息,发送消息是带上form_id.api
*** php代码示例,使用lavavel框架,和easywechat组件 *** public static function SendTpl($uid, $coin, $formId, $page = 'pages/index/index') { $find = User::find($uid); if ($find) { $data = [ 'touser' => $find->openid, 'template_id' => 'Bg7IEAsOqXhFsjkcu3Wdz7Im6HTbBYIdgq_T9EnfcSY', 'page' => $page, 'form_id' => $formId, 'data' => [ 'keyword1' => '您有一笔金币入帐', 'keyword2' => $coin . '金币', 'keyword3' => '哇~有这么多金币呢~~赶快到商店里看看,能够兑换好东西哦~' ] ]; $miniprogram = EasyWeChat::miniProgram(); $miniprogram->template_message->send($data); } }
pages/index/index?pid=12
直接在页面后带参数安全
onLoad: function (options) { if (options.pid) { this.apprentice(options.pid) } }
** js组件的方法列表** methods: { onTapButton(e) { var detail = e.detail.target.dataset.detail detail["formId"] = e.detail.formId ? e.detail.formId : '' console.log('tapbutton', e, detail) this.triggerEvent('tapbutton', { detail: detail, event: e }) // , formId: formId } } *** wxml *** <view class="col-3"> <form bindsubmit="onTapButton" report-submit="{{true}}"> <button class="pannel-btn" type="warn" size="mini" data-detail="{{item}}" plain="{{item.lotery > 0 ? false : true}}" formType="submit">{{item.lotery > 0 ? '兑换' : '补货中'}}</button> </form> </view>
***页面使用*** bindExchange (e) { app.aldstat.sendEvent('商城-商品-' + e.detail.detail.title); wx.navigateTo({ url: '../exchange/exchange' }) }