This article lists several difficult knowledge for developing small programs, I hope it can help everyone.
(Learning video sharing: Programming video)
1. Mini program generates QR code
Mini program generates QR code Mini program generates 2 The QR code actually needs to be called by the backend, and then the frontend can call the backend interface.
In the following example, we pass additional parameters to the backend scene (the maximum length is 32 characters, only supports numbers, uppercase and lowercase English and some special characters: !#$&'()*, /:;=?@-._~, please encode other characters into legal characters by yourself), which are used in the opened applet.
let scene = 't=3&n='+ this.inputVal+'&sale='+this.saleId; request(qcode,{isHyaline:false,qrcodeType:2,scene:scene,width:255,color:{r:'255',g:'255',b:'255'}}) .then(res=>{}) })
The pitfall here is how the front-end obtains the parameters of users by scanning the QR code
onLoad(opts){ var scene = decodeURIComponent(opts.scene); // scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene }
2. Mini program jumps to mini program
The mini program calls toMiniProgram, here I am Made a simple package
function toMiniProgram(appid, path, extraData) { wx.navigateToMiniProgram({ appId: appid, // 要打开的小程序 appId path: path, // 打开的页面路径 envVersion: 'develop', //要打开的小程序版本。仅在当前小程序为开发版或体验版时此参数有效。 extraData: extraData, // 需要传递给目标小程序的数据 success: function (res) { console.log('打开成功') }, fail: function (res) {} }) }
Use
toMiniProgram('appid','pages/customer/goods-detail?id='+id+'&saleId='+this.saleId,{});
on the page to get the parameters in another small program
onLoad(opts){ this.goodsId=opts.id this.saleId=opts.saleId }
3. Implementation of the ceiling effect
The principle of the ceiling effect is to rearrange the tabs scrolled to a certain height into fixed
html
<view class="tab-ctn"> <view class="tabs flex flex-justify {{isTabFixed?'fixed':''}}" id="tabs"> <view class="item pr {{tabIndex===0?'on':''}}" @tap="toggleTab(0)">商品介绍</view> <view class="item pr {{tabIndex===1?'on':''}}" @tap="toggleTab(1)">规格参数</view> </view> </view>
css
.tabs{ padding:0 176rpx; font-size:30rpx; height:90rpx; border-bottom:0.5px solid #E4E4E4;} .item{ height:100%; position:relative; padding-top:20rpx; color:#999; &.on{ color:#FD343B; font-weight:bold; } } .fixed{ position:fixed; top:0; left:0; right:0; z-index:9; }
js
data={ detailTopH:300, } onLoad(){ this.getElHeight('') // tab上面元素的高度 } /**封装根据id获取元素高度 */ getElHeightById(id){ return new Promise(function(resolve,reject){ const query = wx.createSelectorQuery() query.select('#'+id).boundingClientRect() query.selectViewport().scrollOffset() query.exec(function (res) { resolve(res[0].height) }) }) } // 调用 getElHeight(id){ this.getElHeightById(id).then(res=>{ this.detailTopH = res }) } /**监听页面滚动事件 */ onPageScroll(e){ if(e.scrollTop>=this.detailTopH && !this.isTabFixed){ this.isTabFixed=true }else if(e.scrollTop<=this.detailTopH && this.isTabFixed){ this.isTabFixed=false } }
4 , encapsulation timestamp
function formatTime(timestamp, type = "date") { var date = new Date(timestamp); var year = date.getFullYear() var month = date.getMonth() + 1 var day = date.getDate() var hour = date.getHours() var minute = date.getMinutes() var second = date.getSeconds() if (type == "date") { return [year, month, day].map(formatNumber).join('-'); } else if (type == "all") { return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':') } else if (type == "time") { return [hour, minute, second].map(formatNumber).join(':') } else if (type == "time2") { return [hour, minute].map(formatNumber).join(':') } else if (type == 'month') { return [month, day].map(formatNumber).join('-'); } } /**niu 封装时间戳格式化辅助,将年月日先转为字符串,再判断是否加0*/ function formatNumber(n) { n = n.toString() return n[1] ? n : '0' + n } formatTime(1236547891,'all') // 2019-11-02 03:11:11 formatTime(1236547891,'time') // 03:11:22 formatTime(1236547891,'time2') // 03:11 formatTime(1236547891,'month') // 03-03 formatTime(1236547891,'date') // 2019-11-02
Related recommendations:小program development
The above is the detailed content of What are the difficulties in mini program development?. For more information, please follow other related articles on the PHP Chinese website!

随着移动互联网技术和智能手机的普及,微信成为了人们生活中不可或缺的一个应用。而微信小程序则让人们可以在不需要下载安装应用的情况下,直接使用小程序来解决一些简单的需求。本文将介绍如何使用Python来开发微信小程序。一、准备工作在使用Python开发微信小程序之前,需要安装相关的Python库。这里推荐使用wxpy和itchat这两个库。wxpy是一个微信机器

小程序能用react,其使用方法:1、基于“react-reconciler”实现一个渲染器,生成一个DSL;2、创建一个小程序组件,去解析和渲染DSL;3、安装npm,并执行开发者工具中的构建npm;4、在自己的页面中引入包,再利用api即可完成开发。

微信小程序是一种轻量级的应用程序,可以在微信平台上运行,不需要下载安装,方便快捷。Java语言作为一种广泛应用于企业级应用开发的语言,也可以用于微信小程序的开发。在Java语言中,可以使用SpringBoot框架和第三方工具包来开发微信小程序。下面是一个简单的微信小程序开发过程。创建微信小程序首先,需要在微信公众平台上注册一个小程序。注册成功后,可以获取到

实现思路x01服务端的建立首先,在服务端,使用socket进行消息的接受,每接受一个socket的请求,就开启一个新的线程来管理消息的分发与接受,同时,又存在一个handler来管理所有的线程,从而实现对聊天室的各种功能的处理x02客户端的建立客户端的建立就要比服务端简单多了,客户端的作用只是对消息的发送以及接受,以及按照特定的规则去输入特定的字符从而实现不同的功能的使用,因此,在客户端这里,只需要去使用两个线程,一个是专门用于接受消息,一个是专门用于发送消息的至于为什么不用一个呢,那是因为,只

PHP与小程序的地理位置定位与地图显示地理位置定位与地图显示在现代科技中已经成为了必备的功能之一。随着移动设备的普及,人们对于定位和地图显示的需求也越来越高。在开发过程中,PHP和小程序是常见的两种技术选择。本文将为大家介绍PHP与小程序中的地理位置定位与地图显示的实现方法,并附上相应的代码示例。一、PHP中的地理位置定位在PHP中,我们可以使用第三方地理位

本篇文章给大家带来了关于微信小程序的相关问题,其中主要介绍了如何在小程序中用公众号模板消息,下面一起来看一下,希望对大家有帮助。

随着小程序的广泛应用,越来越多的开发者需要将其与后台服务器进行数据交互,其中最常见的业务场景之一就是上传文件。本文将介绍在小程序中实现文件上传的PHP后台实现方法。一、小程序中的文件上传在小程序中实现文件上传,主要依赖于小程序APIwx.uploadFile()。该API接受一个options对象作为参数,其中包含了要上传的文件路径、需要传递的其他数据以及

苏州健康码的小程序叫“苏康码”,它是苏州市疫情防控指挥部指定的通行服务码,疫情防控期间在全市范围内通用,可以作为广大民众日常出行的重要凭证,同时作为防疫人员查验的主要依据;也是省内所有来苏逗苏人员以及在苏工作学习生活,旅游或临时停留人员申报的键康申报数据为基础,结合相关数据比对后动态生成的个人电子健康凭证。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
