이 기사에는 소규모 프로그램 개발에 대한 몇 가지 어려운 지식이 나열되어 있습니다. 모든 사람에게 도움이 되기를 바랍니다.
(학습 영상 공유: 프로그래밍 영상)
1. QR 코드를 생성하는 미니 프로그램
QR 코드를 생성하는 미니 프로그램은 실제로 백엔드 호출이 필요하며, 프론트엔드가 백엔드를 호출합니다. -끝 인터페이스.
다음 예에서는 백엔드 장면에 추가 매개변수를 전달합니다(최대 길이는 32자이며 숫자, 영어 대문자 및 소문자, 일부 특수 문자만 지원합니다: !#$&'()*+,/:; = ?@-._~, 열린 애플릿에서 사용되는 다른 문자를 직접 합법적인 문자로 인코딩하십시오.
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=>{}) })
여기서 함정은 프런트엔드가 QR 코드를 스캔하여 매개변수를 얻는 방법입니다.
onLoad(opts){ var scene = decodeURIComponent(opts.scene); // scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene }
2. 미니 프로그램이 미니 프로그램으로 점프합니다.
여기서 미니 프로그램을 호출합니다
function toMiniProgram(appid, path, extraData) { wx.navigateToMiniProgram({ appId: appid, // 要打开的小程序 appId path: path, // 打开的页面路径 envVersion: 'develop', //要打开的小程序版本。仅在当前小程序为开发版或体验版时此参数有效。 extraData: extraData, // 需要传递给目标小程序的数据 success: function (res) { console.log('打开成功') }, fail: function (res) {} }) }
페이지에서
toMiniProgram('appid','pages/customer/goods-detail?id='+id+'&saleId='+this.saleId,{});
를 사용하여 다른 애플릿에서 매개변수 가져오기
onLoad(opts){ this.goodsId=opts.id this.saleId=opts.saleId }
3. 천장 효과 구현
천장 효과의 원리는 특정 높이로 스크롤된 탭을 고정된 위치로 재배열하는 것입니다
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. 캡슐화 타임스탬프
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
관련 권장 사항: Mini 프로그램 개발
위 내용은 미니프로그램 개발에 있어서 어려운 점은 무엇인가요?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

드림위버 CS6
시각적 웹 개발 도구

mPDF
mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경
