国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁 微信小程序 小程序開發(fā) 總結(jié)分享一些小程序開發(fā)中遇到的問題(幫忙避坑)

總結(jié)分享一些小程序開發(fā)中遇到的問題(幫忙避坑)

Feb 08, 2022 am 10:07 AM
小程序開發(fā) 微信

本篇文章給大家總結(jié)下之前開發(fā)微信小程序的時候遇到過一些問題,并將解決方案分享給大家,希望對大家有所幫助!

總結(jié)分享一些小程序開發(fā)中遇到的問題(幫忙避坑)

請以小程序最新文檔為準(zhǔn)~:

https://developers.weixin.qq.com/ebook?action=get_post_info&docid=0008aeea9a8978ab0086a685851c0a&highline=webview

渲染列表時用 block 包裹

<block wx:for="{{[1, 2, 3]}}">
  <view> {{index}}: </view>
  <view> {{item}} </view>
</block>

block 不會真實渲染到頁面上,只作為一個包裹元素,接受控制屬性

寫一個自定義組件

自定義組件分為 4 部分

  • properties 組件接收的屬性

properties: {
  // 輸入框的默認(rèn)提示
  placeholder: {
	type: String,  // 屬性值的類型
	value: &#39;&#39;      // 屬性默認(rèn)值
  }
},
  • data 組件數(shù)據(jù)

  • methods 組件方法,一般內(nèi)部方法用_開頭

  • 組件的生命周期函數(shù),一般使用 ready,在組件布局完成后執(zhí)行,此時可以獲取節(jié)點信息(使用 SelectorQuery

調(diào)用父組件傳入的方法

// 子組件
var myEventDetail = {value: &#39;&#39;}; // detail對象,提供給事件監(jiān)聽函數(shù),寫需要傳給外面的數(shù)據(jù)
var myEventOption = {} // 觸發(fā)事件的選項
this.triggerEvent(&#39;onclear&#39;, myEventDetail, myEventOption)
<!-- 父組件 -->
<searchbar id="search-bar" bind:onsearch="onSearch" bind:onclear="onSearch" placeholder="搜索文章內(nèi)容"></searchbar>
<!-- 像綁定 bindtap 一樣綁定自定義函數(shù) -->
// 父組件
onSearch(e){
  console.log(e.detail.value)
}

父組件直接調(diào)用子組件的方法

// 父組件,使用 selectComponent 拿到子組件的實例,直接調(diào)用其中的方法
let searchBar = this.selectComponent(&#39;#search-bar&#39;);
searchBar.setData({ value: e.currentTarget.dataset.name })
searchBar.onClickSearch({ detail: {value: e.currentTarget.dataset.name}});

子組件中獲取 dom 寬高

// 獲取屏幕寬度
let windowWidth = wx.getSystemInfoSync().windowWidth
// 在組件內(nèi)部需要寫 this
let query = wx.createSelectorQuery().in(this);
let that = this;
query.selectAll(&#39;.tagItem&#39;).boundingClientRect()
query.exec(function (res) {
	let allWidth = 0;
	res[0].map(item=>{
		allWidth = allWidth + item.width
		return allWidth
	})
	let length = res[0].length
	let ratioWidth = allWidth / windowWidth
	that.setData({
		allLength: length,
		iphone: ratioWidth + (length == 1 ? 0 : res[0].length * 0.0533)
	})
})

頁面返回時不會調(diào)用 onLoad

之前把調(diào)用接口的部分寫到了onLoad里,從文章列表進(jìn)入詳情頁,在從詳情頁點擊左上角回退返回列表頁,列表頁的閱讀數(shù)應(yīng)該更新,但是沒有更新,因為沒有重新調(diào)文章列表接口。

所以把調(diào)文章列表接口的部分寫好了onShow里。

自定義 tabbar 優(yōu)化

第一次優(yōu)化,將組件封裝的tabbar改成頁面的模版形式

1、之前用組件的形式寫的,改為了 template;tabbar 上的圖標(biāo)都改成的 iconfont,解決點擊 tabbar 時候會閃的問題

<template name="tabbar">
	<view class="tabbar-wrapper">
		<block wx:for="{{tabbar.list}}" wx:key="item">
			<navigator hover-class="none" class="tabbar_nav {{item.selected ?&#39;selected&#39;:&#39;&#39;}}"  url="{{item.pagePath}}" style="color:{{item.selected ? tabbar.selectedColor : tabbar.color}}" open-type="reLaunch">
				<view class="tab-item"><text  class="{{item.iconPath}}" style="width: {{item.iconWidth}};height: {{item.iconHeight}}"></text>{{item.text}}<text class=&#39;red-tag&#39; wx:if="{{tabbar.num && index==1}}">{{tabbar.num > 99 ? &#39;99+&#39; : tabbar.num}}</text></view>
			</navigator>
		</block>
	</view>
</template>

2、點擊 tabbar 時,需要銷毀之前的頁面,在跳到需要跳轉(zhuǎn)的頁面,所以在 navigator 組件用了 reLaunch

第二次優(yōu)化,將帶有tabbar的頁面都封裝成組件寫在頁面,在頁面中setData切換tab

<homePage id="home-page" wx:if="{{tabbarID == tabbarList.home}}"  bind:onclicktab="setTabbar"  ></homePage>
<articleLibraryPage  id="article-page" wx:if="{{tabbarID == tabbarList.article}}"></articleLibraryPage>
<doclistPage  id="doctor-page" wx:if="{{tabbarID == tabbarList.doctor}}"></doclistPage>
<mePage id="me-page" wx:if="{{tabbarID == tabbarList.me}}"></mePage>
<tabbar id="tab-bar" bind:onclick="onClickTabbar"  tabbarID="{{tabbarID}}"></tabbar>

修改的地方:

  • 帶有tabbar的頁面都重寫為組件形式

  • 因為組件中只有掛載完成后的 ready 方法,所以之前頁面中 onShow,onReachBottom,onPullDownRefresh 都放到父頁面調(diào)用

onPullDownRefresh: function () {
	if (this.data.tabbarID === this.data.tabbarList.article) {
	  // 使用 selectComponent 找到組件實例,調(diào)用內(nèi)部方法
	  let articlePage = this.selectComponent(&#39;#article-page&#39;);
	  articlePage.onPullDownRefresh();
	} else if (this.data.tabbarID === this.data.tabbarList.doctor){
	  let doctorPage = this.selectComponent(&#39;#doctor-page&#39;);
	  doctorPage.onPullDownRefresh();
	} else {
	  wx.stopPullDownRefresh();
	}
},

帶來的問題:

  • 每個tabbar都會有下拉刷新的效果,即使不需要下拉刷新

  • 從其他頁面點擊按鈕,直接跳到首頁的某一個tab卡,可能會有問題

使用 iconfont

https://www.jianshu.com/p/1cfc074eeb75

  • 登錄 iconfont.cn 下載 zip 包

  • 解壓縮,其中的 .ttf 文件在 transfonter.org/ 上面轉(zhuǎn)成 base64 格式

  • 將 style.css 寫入新建的 iconfont.wxss 中,上面的字體文件路徑用剛剛轉(zhuǎn)好的 base64 替代

  • 在 app.wxss 中 import iconfont.wxss

注意:組件中的樣式本身不受 app.wxss 影響,因此,組件中需要使用 iconfont 的時候,需要手動引一下 app.wxss 或者 iconfont.wxss

列表的左滑效果

1、在列表的父元素上綁定事件

<view  
	class="list-container"
	wx:for="{{doctorList.list}}"
	wx:key="{{index}}"
>
	<view
		bindtouchstart=&#39;onTouchStartListItem&#39;
		bindtouchmove=&#39;onTouchMoveListItem&#39;
		style="{{item.txtStyle}}"
	>滑動的內(nèi)容
	</view>
	<view class="backCover">滑動后顯示的按鈕</view>
</view>
.list-container{
	position: relative;
	width:100%;
	height: 224rpx;
	overflow: hidden;
}
.list-item{
	position: absolute;
	left: 0;
	z-index: 5;
	transition: left 0.2s ease-in-out;
	background-color: #fff;
}
.backCover{
	box-sizing: border-box;
	width: 200rpx;
	height: 218rpx;
	position: absolute;
	right: 0;
	top: 0;
	z-index: 4;
}

2、通過判斷滑動距離修改列表項的 left 值

onTouchStartListItem: function (e) {
	// 是單指觸碰
	if (e.touches.length === 1) {
		// 記下觸碰點距屏幕邊緣的x軸位置
		this.setData({
			startX: e.touches[0].clientX,
		})
	}
},

onTouchMoveListItem: function (e) {
	var that = this
	if (e.touches.length == 1) {
		var disX = that.data.startX - e.touches[0].clientX;
		var deleteBtnWidth = that.data.deleteBtnWidth;
		var txtStyle = "";
		if (disX < deleteBtnWidth / 4) {
			txtStyle = "left:0rpx";
		} else {
			txtStyle = "left:-" + deleteBtnWidth + "rpx";
		}
		var index = e.currentTarget.id
		var list = that.data.doctorList.list
		list[index].txtStyle = txtStyle;
		that.setData({
			doctorList: {
				list: list,
				total: that.data.doctorList.total
			}
		})
	}
},

  

onTouchEndListItem: function (e) {
	var that = this
	if (e.changedTouches.length == 1) {
		var endX = e.changedTouches[0].clientX;
		var disX = that.data.startX - endX;
		var deleteBtnWidth = that.data.deleteBtnWidth;
		var txtStyle = disX > deleteBtnWidth / 2 ? "left:-" + deleteBtnWidth + "px" : "left:0px";
		var index = e.currentTarget.id
		var list = that.data.doctorList.list
		list[index].txtStyle = txtStyle;
		that.setData({
			doctorList: {
				list: list,
				total: that.data.doctorList.total
			}
		});
	}
},

【相關(guān)學(xué)習(xí)推薦:小程序開發(fā)教程

以上是總結(jié)分享一些小程序開發(fā)中遇到的問題(幫忙避坑)的詳細(xì)內(nèi)容。更多信息請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機

Video Face Swap

Video Face Swap

使用我們完全免費的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級代碼編輯軟件(SublimeText3)

公司安全軟件導(dǎo)致應(yīng)用無法運行?如何排查和解決? 公司安全軟件導(dǎo)致應(yīng)用無法運行?如何排查和解決? Apr 19, 2025 pm 04:51 PM

公司安全軟件導(dǎo)致部分應(yīng)用無法正常運行的排查與解決方法許多公司為了保障內(nèi)部網(wǎng)絡(luò)安全,會部署安全軟件。...

H5頁面制作和微信小程序有什么不同 H5頁面制作和微信小程序有什么不同 Apr 05, 2025 pm 11:51 PM

H5更靈活,可定制性強,但需要嫻熟的技術(shù);小程序上手快,維護(hù)便捷,但受限于微信框架。

H5和小程序與APP的區(qū)別 H5和小程序與APP的區(qū)別 Apr 06, 2025 am 10:42 AM

H5、小程序和APP的主要區(qū)別在于:技術(shù)架構(gòu):H5基于網(wǎng)頁技術(shù),小程序和APP為獨立應(yīng)用程序。體驗和功能:H5輕便易用,功能受限;小程序輕量級,交互性好;APP功能強大,體驗流暢。兼容性:H5跨平臺兼容,小程序和APP受平臺限制。開發(fā)成本:H5開發(fā)成本低,小程序中等,APP最高。適用場景:H5適合信息展示,小程序適合輕量化應(yīng)用,APP適合復(fù)雜功能應(yīng)用。

H5和小程序的開發(fā)工具有哪些 H5和小程序的開發(fā)工具有哪些 Apr 06, 2025 am 09:54 AM

H5開發(fā)工具推薦:VSCode、WebStorm、Atom、Brackets、Sublime Text;小程序開發(fā)工具:微信開發(fā)者工具、支付寶小程序開發(fā)者工具、百度智能小程序IDE、頭條小程序開發(fā)者工具、Taro。

H5和小程序如何選擇 H5和小程序如何選擇 Apr 06, 2025 am 10:51 AM

H5和小程序的選擇取決于需求。對于跨平臺、快速開發(fā)和高擴展性的應(yīng)用,選擇H5;對于原生體驗、豐富功能和平臺依附性的應(yīng)用,選擇小程序。

H5和小程序的推廣方式有何不同 H5和小程序的推廣方式有何不同 Apr 06, 2025 am 11:03 AM

H5與小程序的推廣方式存在差異:平臺依賴性:H5依賴瀏覽器,小程序依賴特定平臺(如微信)。用戶體驗:H5體驗較差,小程序提供類似原生應(yīng)用的流暢體驗。傳播方式:H5通過鏈接傳播,小程序通過平臺分享或搜索。H5推廣方式:社交分享、郵件營銷、QR碼、SEO、付費廣告。小程序推廣方式:平臺推廣、社交分享、線下推廣、ASO、與其他平臺合作。

幣圈最新消息APP排名推薦(2025權(quán)威發(fā)布) 幣圈最新消息APP排名推薦(2025權(quán)威發(fā)布) Apr 21, 2025 pm 09:33 PM

最佳的加密貨幣交易和分析平臺包括:1. OKX:全球交易量第一,支持多種交易,提供AI行情分析和鏈上數(shù)據(jù)監(jiān)控。 2. 幣安:全球最大交易所,提供深度行情和新幣首發(fā)。 3. 芝麻開門:以現(xiàn)貨交易和OTC通道著稱,提供自動化交易策略。 4. CoinMarketCap:權(quán)威行情數(shù)據(jù)平臺,覆蓋20000 幣種。 5. CoinGecko:以社區(qū)情緒分析見長,提供DeFi和NFT趨勢監(jiān)控。 6. 非小號:國內(nèi)行情平臺,提供A股與幣市聯(lián)動分析。 7. 鏈上財經(jīng):專注區(qū)塊鏈新聞,每日更新深度報道。 8. 金色財經(jīng):24小

抖音網(wǎng)頁版入口登錄鏈接地址https 抖音網(wǎng)頁版入口網(wǎng)址免費 抖音網(wǎng)頁版入口登錄鏈接地址https 抖音網(wǎng)頁版入口網(wǎng)址免費 May 22, 2025 pm 04:24 PM

抖音網(wǎng)頁版的登錄入口是https://www.douyin.com/。登錄步驟包括:1.打開瀏覽器;2.輸入網(wǎng)址https://www.douyin.com/;3.點擊“登錄”按鈕并選擇登錄方式;4.輸入賬號密碼;5.完成登錄。網(wǎng)頁版提供了瀏覽、搜索、互動、上傳視頻和個人主頁管理等功能,具有大屏幕體驗、多任務(wù)處理、便捷的賬號管理和數(shù)據(jù)統(tǒng)計等優(yōu)勢。

See all articles