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

Table of Contents
Briefly describe the related file types of WeChat mini programs. " >3. Briefly describe the related file types of WeChat mini programs.
The mini program has What are the methods for passing parameter values? " >4. The mini program has What are the methods for passing parameter values?
The WeChat applet sets the id method identifier to pass the value
Get the value passed by id
通過使用data - xxxx 的方法標(biāo)識來傳值
如何獲取data-xxxx傳遞的值?
微信小程序如何跨頁面獲取值?
5. 簡述下wx.navigateTo(), wx.redirectTo(), wx.switchTab(), wx.navigateBack(), wx.reLaunch()的區(qū)別?" >5. 簡述下wx.navigateTo(), wx.redirectTo(), wx.switchTab(), wx.navigateBack(), wx.reLaunch()的區(qū)別?
6. 如果需要用戶授權(quán),用戶選擇拒絕授權(quán),此時應(yīng)該如何處理?" >6. 如果需要用戶授權(quán),用戶選擇拒絕授權(quán),此時應(yīng)該如何處理?
wx.getUserInfo(OBJECT)
7. 你平時封裝可以復(fù)用的方法嗎?你會把可以復(fù)用的方法寫在哪個文件里?" >7. 你平時封裝可以復(fù)用的方法嗎?你會把可以復(fù)用的方法寫在哪個文件里?
8. 分析下小程序的優(yōu)劣勢?" >8. 分析下小程序的優(yōu)劣勢?
9. 設(shè)置值到頁面暫存區(qū)(即data)里面的方法有幾種?分別是什么?有什么區(qū)別?" >9. 設(shè)置值到頁面暫存區(qū)(即data)里面的方法有幾種?分別是什么?有什么區(qū)別?
微信小程序--data的賦值與取值" >微信小程序--data的賦值與取值
10. 如何檢測用戶的微信版本是否支持某項功能?" >10. 如何檢測用戶的微信版本是否支持某項功能?
11. 如何分包加載?分包加載的優(yōu)勢在哪?" >11. 如何分包加載?分包加載的優(yōu)勢在哪?
12. 在你開發(fā)小程序的過程中遇到過什么坑? 你是怎么解決的?" >12. 在你開發(fā)小程序的過程中遇到過什么坑? 你是怎么解決的?
Home WeChat Applet Mini Program Development Summarize and solve problems encountered in mini program development

Summarize and solve problems encountered in mini program development

Apr 28, 2021 am 10:13 AM
Mini program development

Summarize and solve problems encountered in mini program development

小program interview questions

1. What is the difference between bindtap and catchtap?

bindEvent binding will not prevent bubbling events from bubbling up. catchEvent binding It can definitely prevent bubbling events from bubbling upward

2. Js array is converted to a string, forced to be converted to an integer and converted to a floating point number What are the functions?

js provides two conversion functions: parseInt() and parseFloat(). The former converts the value to an integer, and the latter converts the value to a floating point number. Only by calling these methods on the String type can these two functions run correctly; for other types, NaN (Not a Number) is returned.

Related free learning recommendations: WeChat Mini Program Development

1. Conversion function:

#Both parseInt() and parseFloat() will carefully analyze the string before determining whether it is a numeric value. The parseInt() method first checks the character at position 0 to determine whether it is a valid number; if not, the method will return NaN and will not continue to perform other operations. But if the character is a valid number, the method will look at the character at position 1 and perform the same test. This process will continue until a character that is not a valid number is found, at which time parseInt() will convert the string before the character into a number.

parseInt("1234blue"); //returns 1234 
parseInt("0xA"); //returns 10 
parseInt("22.5"); //returns 22 
parseInt("blue"); //returns NaN


2. Forced type conversion

You can also use type casting to process the type of the converted value. Use a cast to access a specific value, even if it is of another type.
The three types of forced type conversions available in ECMAScript are as follows:
Boolean(value) - Convert the given value to Boolean type;
Number(value)——Convert the given value into a number (can be an integer or floating point number);
String(value)——Convert the given value into a character string.

3. Use weak type conversion of js variables

Take a small example and you will understand it at a glance .

<script> 
var str= &#39;012.345 &#39;; 
var x = str-0; 
x = x*1;
</script>


##The above example takes advantage of the weakness of js The characteristics of the type are that it only performs arithmetic operations and realizes type conversion from string to number, but this method is not recommended.

Mini program: pages ——index: index.js(

Page logic) /index.wxml (Page structure)/index.wxss (Page Style sheet) / index.json (Page configuration)

App.js

Mini program logic

App.json

Mini program public settings

App.wxss

Mini program public style sheet

4. The mini program has What are the methods for passing parameter values?

1. Set the id method to identify the parameter value passed after the jump;

2. Use the data - xxxx method to identify the value to be passed

The WeChat applet sets the id method identifier to pass the value

At the item to be jumped, set an id and assign the corresponding value to the current id The key value, such as the id of a movie (then go to the next page with the id to query for detailed information) such as:

After that, we obtain it in the response event of bindtap in js and pass it to the next page. In an interface;

Get the value passed by id

Get the set id value through e.currentTarget.id; and set the global object's Method to pass values,
Get the global object
var app=getApp(); //Set the parameters passed by the global request access app.requestDetailid=id;

Tip: In fact, we can also view the id value of each item we set in wxml

通過使用data - xxxx 的方法標(biāo)識來傳值

通過使用data - xxxx 的方法標(biāo)識來傳值,xxxx可以自定義取名 比如data-key等等都可以。

如何獲取data-xxxx傳遞的值?

在js的bindtap的響應(yīng)事件中:

通過數(shù)據(jù)解析一層層找到數(shù)據(jù),var id=e.target.dataset.id(根據(jù)你的data-id的取名)

微信小程序如何跨頁面獲取值?

依據(jù)上面的方式設(shè)置要傳遞的值,頁面跳轉(zhuǎn)后,我們就需要在下一個頁面拿到傳遞的數(shù)據(jù)(這個數(shù)據(jù)在傳遞前,就已經(jīng)被設(shè)置成全局變量

在跳轉(zhuǎn)后的js頁面,接收傳遞過來的數(shù)據(jù)detail.js

同樣通過全局額方式取值出來,(即和app.js中取某個變量的值是一樣的)

var movieid=getApp().MovieDetailid;
console.log(movieid);

5. 簡述下wx.navigateTo(), wx.redirectTo(), wx.switchTab(), wx.navigateBack(), wx.reLaunch()的區(qū)別?

微信小程序 跳轉(zhuǎn)頁面

小程序頁面有2種跳轉(zhuǎn),可以在wxml頁面或者js中:

1,在wxml頁面中:

<navigator url="../index/index">跳轉(zhuǎn)到新頁面</navigator>
<navigator url="../index/index" open-type="redirect">在當(dāng)前頁打開</navigator>
<navigator url="../index/index" open-type="switchTab">切換到首頁Tab</navigator>

2,在js頁面中:

【注意】此處注意兩個關(guān)鍵詞 “應(yīng)用內(nèi)的頁面” 和 “tabBar頁面”。 app.json文件中tabBar中注冊過的tab頁,即為“tabBar頁面”,非tabBar中注冊占用的頁面即為“應(yīng)用內(nèi)的頁面” 。 如下圖:home頁面為“應(yīng)用內(nèi)的頁面”,index和logs頁面則為 “tabBar頁面”。

3,如果上述跳轉(zhuǎn)遇到跳轉(zhuǎn)失敗或無效的問題,請訪問下面鏈接:

wx.navigateTo/wx.redirectTo 無效

6. 如果需要用戶授權(quán),用戶選擇拒絕授權(quán),此時應(yīng)該如何處理?

在微信小程序開發(fā)時,當(dāng)我們調(diào)用API wx.getUserInfo(OBJECT) 時,需要用戶授權(quán)。但如果用戶拒絕授權(quán),我們?nèi)绾渭嫒萦脩艟芙^授權(quán)狀態(tài),擁有更好的用戶體驗?zāi)兀?/p>

先看看這個接口的官方文檔:

wx.getUserInfo(OBJECT)

獲取用戶信息,需要先調(diào)用 wx.login 接口。

OBJECT參數(shù)說明:

參數(shù)名

類型

必填

說明

withCredentials

Boolean

是否帶上登錄態(tài)信息

success

Function

接口調(diào)用成功的回調(diào)函數(shù)

fail

Function

接口調(diào)用失敗的回調(diào)函數(shù)

complete

Function

接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

1. tip: wx.getUserInfo 接口需要用戶授權(quán),請兼容用戶拒絕授權(quán)的場景。

我們就是要在用戶點擊拒絕的時候,彈出提示框,提示用戶以提升用戶體驗。像下面這樣的。

用具體代碼實現(xiàn)就是,將彈窗寫在 wx.getUserInfo 的fail回調(diào)函數(shù)中,像下面這樣:

wx.getUserInfo({
success: function (resuser) {
console.log(success)
},
fail: function () {// 調(diào)用微信彈窗接口
wx.showModal({
title: &#39;警告&#39;,
content: &#39;您點擊了拒絕授權(quán),將無法正常使用******的功能體驗。請10分鐘后再次點擊授權(quán),或者刪除小程序重新進(jìn)入。&#39;,
success: function (res) {
if (res.confirm) {
console.log(&#39;用戶點擊確定&#39;)
}
}
})
}
})


這樣用戶就獲得了提示信息,但此時,用戶還是停留在頁面的,如果某些展示信息,還是給要給用戶展示的,只是在進(jìn)行某些操作的時候要對授權(quán)進(jìn)行驗證的話,那就得繼續(xù)修改我們的代碼,保存用戶的登錄態(tài),在其他地方做驗證使用。

第一種思路:

保存登錄態(tài)這里是這樣的,將用戶的登錄信息傳給后臺,后臺保存用戶信息,同時用 open_id 在后臺換取一個SessionId 用換取的這個SessionId 存在緩存,做為登錄態(tài)驗證。

wx.getUserInfo({
success: function (resuser) {
let userInfo = resuser.userInfo
that.healthApi.login(code, userInfo).then(logindata => {   // 這里將微信的請求封裝成Promiese 風(fēng)格
if (logindata.code === 0) {
var sessionId = logindata.data// 調(diào)用微信wechat.setStorage將換回來的 SessionId 存在本地緩存
that.wechat.setStorage(&#39;sessionId&#39;, sessionId).then(() => {
that.globalData.userInfo = userInfo
typeof cb == "function" && cb(that.globalData.userInfo)
})
}
})
},
fail: function () {
wx.showModal({
title: &#39;警告&#39;,
content: &#39;您點擊了拒絕授權(quán),將無法正常使用*****的功能體驗。請10分鐘后再次點擊授權(quán),或者刪除小程序重新進(jìn)入。&#39;,
success: function (res) {
if (res.confirm) {
console.log(&#39;用戶點擊確定&#39;)
}
}
})
}
})


這樣我們將登錄態(tài)保存在了 SessionId 中,在每次登錄的時候我們只需要再調(diào)用一個 檢查 SessionId的接口就行,檢查不通過再調(diào)微信登錄接口。此處不做延伸了。

第二種思路:

在3.29微信小程序更新的版本中,加入了這樣一條屬性

withCredentials 字段基礎(chǔ)庫版本 1.1.0 開始支持,低版本需做兼容處理

這個字段的意思就是調(diào)用 wx.getUserInfo(OBJECT) 是否帶上 登錄態(tài) 的信息。

官方文檔是這樣解釋的:

withCredentials 字段基礎(chǔ)庫版本 1.1.0 開始支持,低版本需做兼容處理

注:當(dāng) withCredentials 為 true 時,要求此前有調(diào)用過 wx.login 且登錄態(tài)尚未過期,此時返回的數(shù)據(jù)會包含 encryptedData, iv 等敏感信息;當(dāng) withCredentials 為 false 時,不要求有登錄態(tài),返回的數(shù)據(jù)不包含 encryptedData, iv 等敏感信息。

success返回參數(shù)說明:

參數(shù)

類型

說明

userInfo

OBJECT

用戶信息對象,不包含 openid 等敏感信息

rawData

String

不包括敏感信息的原始數(shù)據(jù)字符串,用于計算簽名。

signature

String

使用 sha1( rawData + sessionkey ) 得到字符串,用于校驗用戶信息。

encryptedData

String

包括敏感數(shù)據(jù)在內(nèi)的完整用戶信息的加密數(shù)據(jù),詳細(xì)見加密數(shù)據(jù)解密算法

iv

String

加密算法的初始向量,詳細(xì)見加密數(shù)據(jù)解密算法

注:需要兼容微信低版本,向后兼容。

那么利用這個接口,我們可以直接拿到 登錄狀態(tài),在其他需要驗證登錄的地方進(jìn)行提示,而在不需要授權(quán)的地方還可以讓用戶瀏覽小程序。

回到前面的問題,在用戶點擊拒絕授權(quán)后,在某些操作時需要驗證用戶是否授權(quán)過,彈出交互信息,那么就利用上面的 SessionId或者 withCredentials 登錄態(tài)進(jìn)行下面的操作:

applyIn: function applyIn() {
if (wx.getStorageSync(&#39;sessionId&#39;)) {  // 根據(jù)儲存的sessionId 進(jìn)行驗證
wx.navigateTo({
url: &#39;familyDoctorApply/familyDoctorApply?Oid=&#39; + this.data.params.Oid + &#39;&title=&#39; + this.data.params.title + &#39;&serviceCity=&#39; + this.data.array[this.data.index].name + &#39;&productPrice=&#39; + this.data.product.productPrice
});
} else {
wx.showModal({
title: &#39;警告&#39;,
content: &#39;您點擊了拒絕授權(quán),無法使用此功能。&#39;,
success: function (res) {
if (res.confirm) {
console.log(&#39;用戶點擊確定&#39;)
}
}
})
}


效果像這樣:

這樣一個簡單完整的登錄及授權(quán),登錄態(tài)保存等前端微信小程序解決方案就完成了,還可以繼續(xù)擴(kuò)展到登錄有效期,退出登錄,用戶權(quán)限等跟多擴(kuò)展的地方。

7. 你平時封裝可以復(fù)用的方法嗎?你會把可以復(fù)用的方法寫在哪個文件里?

其實可以模擬一些框架的,比如bootsrap,寫個demo出來,抽出css和js,js最好抽象成對象(構(gòu)造函數(shù))或者是帶參數(shù)的方法,然后你只要聲明對像,或者參數(shù)指定某個class或id,就可以了

寫在html文件里有什么優(yōu)點嗎?
獨立出來會有什么問題嗎?尤其是載入頁面的時候,應(yīng)該會多發(fā)很多http請求吧,會不會造成加載變慢?

8. 分析下小程序的優(yōu)劣勢?

小程序是在微信生態(tài)發(fā)展過程中新出現(xiàn)的一種應(yīng)用形態(tài),小程序的小,從某種程度上已經(jīng)說明了它的體量不會很大,但是可以實現(xiàn)一些功能相對簡單、交互相對簡單的服務(wù)需求,同時解決了App長期以來多平臺適配、多應(yīng)用市場分發(fā)、開發(fā)成本居高不下等諸多方面的問題。所以小程序【密件】依靠微信平臺和自身“閱后即焚”的功能,獲得眾多年輕人的好評

優(yōu)勢:

1)容易上手,只要之前有HTML+CSS+JS基礎(chǔ)知識,寫小程序基本上沒有大問題;當(dāng)然如果了解ES6+CSS3則完全可以編寫出即精簡又動感的小程序;

2)基本上不需要考慮兼容性問題,只要微信可以正常運行的機(jī)器,就可以運行小程序;

3)基本組件庫已經(jīng)比較齊全:Toast,Loading框,Picker,定位及地圖,Image,Input,Checkbox,Text,TextArea,ScrollView等常用的組件都有,而且使用也挺簡單、方便;

4)發(fā)布、審核高效,基本上上午發(fā)布審核,下午就審核通過,升級簡單,而且支持灰度發(fā)布;

5 ) 微信官方提供使用人數(shù)、頻率等數(shù)據(jù)統(tǒng)計,小程序js腳本執(zhí)行錯誤日志;

6)開發(fā)文檔比較完善,開發(fā)社區(qū)比較活躍;

7)最近剛開放的牛x功能,新增webview組件,可以展示網(wǎng)頁啦,這個比較爽;

8)支持插件式開發(fā),一些基本功能可以開發(fā)成插件,供多個小程序調(diào)用;

劣勢:

1)后臺調(diào)試麻煩,因為API接口必須https請求,且公網(wǎng)地址,也就是說后臺代碼必須發(fā)布到遠(yuǎn)程服務(wù)器上;當(dāng)然我們可以修改host進(jìn)行dns映射把遠(yuǎn)程服務(wù)器轉(zhuǎn)到本地,或者開啟tomcat遠(yuǎn)程調(diào)試;不管怎么說終歸調(diào)試比較麻煩。

2)前臺測試有諸多坑,最頭疼莫過于模擬器與真機(jī)顯示不一致(之前碰到一個案例,后續(xù)單獨講解)

3)真機(jī)測試,個別功能安卓和蘋果表現(xiàn)迥異,我們的小程序里有很多頁面有定位功能,模擬器和iphone定位瞬間完成,然而安卓手機(jī)就蛋疼了,老顯示“定位中...”要很久才能定位好。后來沒辦法只能優(yōu)化,減少定位次數(shù)。

4)native組件,展示很不好,比如textarea,不能在滾動頁面出現(xiàn),而且至于頂層,經(jīng)常其它組件會被它遮擋,點擊其它組件時,就進(jìn)入textarea輸入框;畫布組件也是如此;

5)頁面跳轉(zhuǎn)深度不能超過5個頁面,這個比較麻煩,有些復(fù)雜的頁面跳轉(zhuǎn)沒法實現(xiàn),不過太復(fù)雜的話也有悖小程序簡單易用的原則啦;

6)小程序升級問題,官方文檔說會自動更新,實際情況往往是要先把原來的小程序刪除掉,重新搜索添加,才能加載最新版本;

7)頁面渲染穩(wěn)定性有待提高,已經(jīng)好幾次出現(xiàn)部分用戶的頁面顯示異常,整個頁面被放大了好幾倍,先刪除原來小程序再添加回來,如此重復(fù)好幾次,才能顯示正常;

8)js引用只能使用絕對路徑,很蛋疼;基于安全性及MINA框架實現(xiàn)原理,小程序中對js使用做了很多限制,不能使用:new Function,eval,Generator,不能操作cookie,不能操作DOM;

9)開發(fā)工具bug比較多且效率比較低,三天兩頭升級,解決老問題的同時又出現(xiàn)問題;文件查找、資源定位、代碼編輯較eclipse有一定差距。經(jīng)常出現(xiàn)把a.js當(dāng)做b.js來修改

9. 設(shè)置值到頁面暫存區(qū)(即data)里面的方法有幾種?分別是什么?有什么區(qū)別?

1. 使用QueryString變量
QueryString是一種非常簡單的傳值方式,他可以將傳送的值顯示在瀏覽器的地址欄中。如果是傳遞一個或多個安全性要求不高或是結(jié)構(gòu)簡單的數(shù)值時,可以使用這個方法。但是對于傳遞數(shù)組或?qū)ο蟮脑?,就不能用這個方法了。下面是一個例子:
a.aspx的C#代碼

private void Button1_Click(object sender, System.EventArgs e) 
{ 
 string s_url; 
 s_url = "b.aspx?name=" + Label1.Text; 
 Response.Redirect(s_url); 
}



b.aspx中C#代碼

private void Page_Load(object sender, EventArgs e) 
{ 
 Label2.Text = Request.QueryString["name"]; 
}



2. 使用Application 對象變量
Application對象的作用范圍是整個全局,也就是說對所有用戶都有效。其常用的方法用Lock和UnLock。
a.aspx的C#代碼

private void Button1_Click(object sender, System.EventArgs e) 
{ 
 Application["name"] = Label1.Text; 
 Server.Transfer("b.aspx"); 
}



b.aspx中C#代碼

private void Page_Load(object sender, EventArgs e) 
{ 
 string name; 
 Application.Lock(); 
 name = Application["name"].ToString(); 
 Application.UnLock(); 
}



3. 使用Session變量
想必這個肯定是大家使用中最常見的用法了,其操作與Application類似,作用于用戶個人,所以,過量的存儲會導(dǎo)致服務(wù)器內(nèi)存資源的耗盡。
a.aspx的C#代碼

private void Button1_Click(object sender, System.EventArgs e) 
{ 
 Session["name"] = Label.Text; 
}



b.aspx中C#代碼

private void Page_Load(object sender, EventArgs e) 
{ 
 string name; 
 name = Session["name"].ToString(); 
}



4. 使用Cookie對象變量
這個也是大家常使用的方法,與Session一樣,其是什對每一個用戶而言的,但是有個本質(zhì)的區(qū)別,即Cookie是存放在客戶端的,而session是存放在服務(wù)器端的。而且Cookie的使用要配合ASP.NET內(nèi)置對象Request來使用。

a.aspx的C#代碼

private void Button1_Click(object sender, System.EventArgs e) 
{ 
 HttpCookie cookie_name = new HttpCookie("name"); 
 cookie_name.Value = Label1.Text; 
 Reponse.AppendCookie(cookie_name); 
 Server.Transfer("b.aspx"); 
}



b.aspx中C#代碼

private void Page_Load(object sender, EventArgs e) 
{ 
 string name; 
 name = Request.Cookie["name"].Value.ToString(); 
}



5. 使用Server.Transfer方法
這個才可以說是面象對象開發(fā)所使用的方法,其使用Server.Transfer方法把流程從當(dāng)前頁面引導(dǎo)到另一個頁面中,新的頁面使用前一個頁面的應(yīng)答流,所以這個方法是完全面象對象的,簡潔有效。
a.aspx的C#代碼

public string Name 
{ 
 get{ return Label1.Text;} 
} 
private void Button1_Click(object sender, System.EventArgs e) 
{ 
 Server.Transfer("b.aspx"); 
} 
b.aspx中C#代碼 
private void Page_Load(object sender, EventArgs e) 
{ 
 a newWeb; //實例a窗體 
 newWeb = (source)Context.Handler; 
 string name; 
 name = newWeb.Name; 
}


微信小程序--data的賦值與取值

通過小程序官方文檔可知:

Page() 函數(shù)用來注冊一個頁面。接受一個 object 參數(shù),其指定頁面的初始數(shù)據(jù)、生命周期函數(shù)、事件處理函數(shù)等。其中的參數(shù)data用來設(shè)置初始數(shù)據(jù),WXML 中的動態(tài)數(shù)據(jù)均來自對應(yīng) Page 的 data。

所以如果頁面需要顯示動態(tài)數(shù)據(jù)必須要把數(shù)據(jù)更新到data中對應(yīng)的變量中。

· 頁面js文件中這么寫:

Page({
  data: {
    message: &#39;Hello MINA!&#39;
  }
})
· wxml中這么寫:
<view> {{ message }} </view>
· 如果該數(shù)據(jù)在操作過程中發(fā)生變化,需要將新數(shù)據(jù)重新綁定到該變量中,寫法如下:
function setData(){
    var that = this;
    that.setData({
      message: &#39;新消息&#39;
    })
}
· 如果想在js文件中使用data中的數(shù)據(jù)寫法如下:
function getData(){
    var that = this;
    console.log(that.data.message)
}


10. 如何檢測用戶的微信版本是否支持某項功能?

第一期開放的接口,不是不能使用,而是無需檢測,全部都是支持的。
只有后面最新開放的一些接口,才需要檢測是否支持。
目前開放的所有接口:


onMenuShareTimeline
onMenuShareAppMessage
onMenuShareQQ
onMenuShareWeibo
onMenuShareQZone
startRecord
stopRecord
onVoiceRecordEnd
playVoice
pauseVoice
stopVoice
onVoicePlayEnd
uploadVoice
downloadVoice
chooseImage
previewImage
uploadImage
downloadImage
translateVoice
getNetworkType
openLocation
getLocation
hideOptionMenu
showOptionMenu
hideMenuItems
showMenuItems
hideAllNonBaseMenuItem
showAllNonBaseMenuItem
closeWindow
scanQRCode
chooseWXPay
openProductSpecificView
addCard
chooseCard
openCard

11. 如何分包加載?分包加載的優(yōu)勢在哪?

分包加載的介紹
大部分小程序都會由某幾個功能組成,通常這幾個功能之間是獨立的,但會依賴一些公共的邏輯,并且這些功能通常會對應(yīng)某幾個獨立的頁面。那么小程序代碼的打包,大可不必一定要打成一個,可以按照功能的劃分,拆分成幾個分包,當(dāng)需要用到某個功能時,才加載這個功能對應(yīng)的分包。
對于用戶來說,小程序加載流程變成了:
1.首次啟動時,先下載小程序主包,顯示主包內(nèi)的頁面;
2.如果用戶進(jìn)入了某個分包的頁面,再下載這個對應(yīng)分包,下載完畢后,顯示分包的頁面。
采用分包加載,對開發(fā)者而言,能使小程序有更大的代碼體積,承載更多的功能與服務(wù);而對用戶而言,可以更快地打開小程序,同時在不影響啟動速度前提下使用更多功能。
分包的劃分
在配置前首先需要開發(fā)者規(guī)劃下各個分包需要容納的內(nèi)容,我們建議開發(fā)者按照功能劃分的的原則,將同一個功能下的頁面和邏輯放置于同一個目錄下,對于一些跨功能之間公共邏輯,將其放置于主包下,這樣可以確保在分包引用這部分功能時,這部分的邏輯一定存在。
在分包劃分時,應(yīng)該注意以下事項:
1.避免分包與分包之間引用上的耦合。因為分包的加載是由用戶操作觸發(fā)的,并不能確保某分包加載時,另外一個分包就一定存在,這個時候可能會導(dǎo)致 JS 邏輯異常的情況,例如報「"xxx.js" is not defined」這樣的錯誤;
2.一些公共用到的自定義組件,需要放在主包內(nèi)。
分包的配置
當(dāng)理清了分包的劃分后,就可以進(jìn)行分包的配置了,這一步并不復(fù)雜。

假設(shè)支持分包的小程序目錄結(jié)構(gòu)如下:

開發(fā)者通過在 app.json subPackages 字段聲明項目分包結(jié)構(gòu):

分包加載的低版本兼容問題
微信 6.6.0 版本開始支持分包加載,而對于低于這個版本的客戶端,我們做了兼容處理,開發(fā)者不需要對老版本微信客戶端做兼容。對于老版本的客戶端,編譯后臺會將所有的分包打包成一個整包,老版本的客戶端依然按照整包的方式進(jìn)行加載。
所以在老版本的微信客戶端下,是依然采取整包加載的方式加載的,建議開發(fā)者盡量控制代碼包的大小。
目前小程序分包大小的限制:
整個小程序所有分包大小不超過 4M
單個分包/主包大小不能超過 2M
隨著時間推移,老版本覆蓋率降低,我們會考慮進(jìn)一步擴(kuò)大代碼包的大小。

12. 在你開發(fā)小程序的過程中遇到過什么坑? 你是怎么解決的?

1.我們使用app.json文件來對微信小程序進(jìn)行全局配置,決定頁面文件的路徑、窗口表現(xiàn)、設(shè)置網(wǎng)絡(luò)超時時間、設(shè)置多 tab 的時候在pages中寫注釋的時候回報錯。
例如:

{
  "pages":[
      //這是首頁面
    "pages/welcome/welcome"
  ]}


此時就會報錯


2.在json文件中沒有寫內(nèi)容的時候也要加一對大括號{ },不然的話也會報錯

3. ①在開發(fā)微信小程序的時候,我們使用app.json文件來對微信小程序進(jìn)行全局配置,決定頁面文件的路徑,窗口表現(xiàn),設(shè)置網(wǎng)絡(luò)超時時間,設(shè)置多Tab等。
以下是一個包含了所有配置選項的簡單配置,app.json :

{
  //設(shè)置頁面路徑
  "pages": [
    "pages/index/index",
    "pages/logs/index"
  ],
  //設(shè)置默認(rèn)頁面的窗口表現(xiàn)
  "window": {
    "navigationBarTitleText": "Demo"
  },
  //設(shè)置底部 tab 的表現(xiàn)
  "tabBar": {
    "list": [{
      "pagePath": "pages/index/index",
      "text": "首頁"
    }, {
      "pagePath": "pages/logs/logs",
      "text": "日志"
    }]
  },
  //設(shè)置網(wǎng)絡(luò)超時時間
  "networkTimeout": {
    "request": 10000,
    "downloadFile": 10000
  },
  //設(shè)置是否開啟 debug 模式
  "debug": true
}


②但是在對頁面json文件進(jìn)行配置的時候只可以配置設(shè)置默認(rèn)頁面的窗口表現(xiàn)(即只能對window進(jìn)行配置),但是在此時可以直接省略window,如果加window則沒有效果,也不會報錯。
以下是一個包含了window配置選項的簡單配置,post.json :

注意:這是錯誤的寫法

{
  "window":{
    "navigationBarBackgroundColor": "#ffffff",
    "navigationBarTextStyle": "black",
    "navigationBarTitleText": "微信接口功能演示",
    "backgroundColor": "#eeeeee",
    "backgroundTextStyle": "light"
  }}


注意:正確的寫法

{
    "navigationBarBackgroundColor": "#ffffff",
    "navigationBarTextStyle": "black",
    "navigationBarTitleText": "微信接口功能演示",
    "backgroundColor": "#eeeeee",
    "backgroundTextStyle": "light"}


4.此前一直沒有注意vertical-align: middle和height:40rpx;line-height:40rpx進(jìn)行設(shè)置垂直劇中的區(qū)別,這次主要說一下vertical-align: middle
代碼如下:

<view class="post-author-date">
    <image class="post-author" src="../../images/avatar/1.png">
    </image>
    <text class="post-date">Nov 15 2016</text>
</view>
 
.post-author{
    width: 60rpx;
    height: 60rpx;
    vertical-align: middle;
}
.post-date{
    margin-top: 5rpx;
    vertical-align: middle;
    /*height: 40rpx;
    line-height: 40rpx;*/
}

總結(jié):?
①vertical-align: middle;把此元素放在父元素的中部?
②當(dāng)一個父元素里面有多個子元素,需要把幾個子元素水平對齊,并且每個子元素都垂直劇中的時候,對每一個子元素進(jìn)行設(shè)置 vertical-align: middle?
③height: 40rpx; line-height: 40rpx;可以對文本進(jìn)行垂直居中

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

The above is the detailed content of Summarize and solve problems encountered in mini program development. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
PHP security protection and attack prevention in mini program development PHP security protection and attack prevention in mini program development Jul 07, 2023 am 08:55 AM

PHP security protection and attack prevention in mini program development With the rapid development of the mobile Internet, mini programs have become an important part of people's lives. As a powerful and flexible back-end development language, PHP is also widely used in the development of small programs. However, security issues have always been an aspect that needs attention in program development. This article will focus on PHP security protection and attack prevention in small program development, and provide some code examples. XSS (Cross-site Scripting Attack) Prevention XSS attack refers to hackers injecting malicious scripts into web pages

PHP page jump and routing management in mini program development PHP page jump and routing management in mini program development Jul 04, 2023 pm 01:15 PM

PHP's page jump and routing management in mini program development With the rapid development of mini programs, more and more developers are beginning to combine PHP with mini program development. In the development of small programs, page jump and routing management are very important parts, which can help developers achieve switching and navigation operations between pages. As a commonly used server-side programming language, PHP can interact well with mini programs and transfer data. Let’s take a detailed look at PHP’s page jump and routing management in mini programs. 1. Page jump base

PHP permission management and user role setting in mini program development PHP permission management and user role setting in mini program development Jul 04, 2023 pm 04:48 PM

PHP permission management and user role setting in mini program development. With the popularity of mini programs and the expansion of their application scope, users have put forward higher requirements for the functions and security of mini programs. Among them, permission management and user role setting are An important part of ensuring the security of mini programs. Using PHP for permission management and user role setting in mini programs can effectively protect user data and privacy. The following will introduce how to implement this function. 1. Implementation of Permission Management Permission management refers to granting different operating permissions based on the user's identity and role. in small

How to implement small program development and publishing in uniapp How to implement small program development and publishing in uniapp Oct 20, 2023 am 11:33 AM

How to develop and publish mini programs in uni-app With the development of mobile Internet, mini programs have become an important direction in mobile application development. As a cross-platform development framework, uni-app can support the development of multiple small program platforms at the same time, such as WeChat, Alipay, Baidu, etc. The following will introduce in detail how to use uni-app to develop and publish small programs, and provide some specific code examples. 1. Preparation before developing small programs. Before starting to use uni-app to develop small programs, you need to do some preparations.

Implementation method of drop-down menu developed in PHP in WeChat applet Implementation method of drop-down menu developed in PHP in WeChat applet Jun 04, 2023 am 10:31 AM

Today we will learn how to implement the drop-down menu developed in PHP in the WeChat applet. WeChat mini program is a lightweight application that users can use directly in WeChat without downloading and installing, which is very convenient. PHP is a very popular back-end programming language and a language that works well with WeChat mini programs. Let's take a look at how to use PHP to develop drop-down menus in WeChat mini programs. First, we need to prepare the development environment, including PHP, WeChat applet development tools and servers. then we

PHP data caching and caching strategies in small program development PHP data caching and caching strategies in small program development Jul 05, 2023 pm 02:57 PM

PHP data caching and caching strategies in mini program development With the rapid development of mini programs, more developers are beginning to pay attention to how to improve the performance and response speed of mini programs. One of the important optimization methods is to use data caching to reduce frequent access to the database and external interfaces. In PHP, we can use various caching strategies to implement data caching. This article will introduce the principles of data caching in PHP and provide sample codes for several common caching strategies. 1. Data caching principle Data caching refers to storing data in memory to

PHP page animation effects and interaction design in mini program development PHP page animation effects and interaction design in mini program development Jul 04, 2023 pm 11:01 PM

Introduction to PHP page animation effects and interaction design in mini program development: A mini program is an application that runs on a mobile device and can provide an experience similar to native applications. In the development of mini programs, PHP, as a commonly used back-end language, can add animation effects and interactive design to mini program pages. This article will introduce some commonly used PHP page animation effects and interaction designs, and attach code examples. 1. CSS3 animation CSS3 provides a wealth of properties and methods for achieving various animation effects. And in small

UniApp implements analysis of the development and launch process of ByteDance mini-programs UniApp implements analysis of the development and launch process of ByteDance mini-programs Jul 06, 2023 pm 05:01 PM

Analysis of the development and launch process of ByteDance applets implemented by UniApp. As an emerging mobile application development method, ByteDance applets are gradually becoming popular in the industry. Before developing the Bytedance mini program, we need to understand how to use UniApp to implement the development and launch process. 1. Introduction to UniApp UniApp is a framework developed based on Vue.js that uses HTML5, App, and small programs as the unified development framework for multiple terminals. By writing a set of code, it can run on multiple platforms at the same time, including fonts.

See all articles