亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

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
通過(guò)使用data - xxxx 的方法標(biāo)識(shí)來(lái)傳值
如何獲取data-xxxx傳遞的值?
微信小程序如何跨頁(yè)面獲取值?
5. 簡(jiǎn)述下wx.navigateTo(), wx.redirectTo(), wx.switchTab(), wx.navigateBack(), wx.reLaunch()的區(qū)別?" >5. 簡(jiǎn)述下wx.navigateTo(), wx.redirectTo(), wx.switchTab(), wx.navigateBack(), wx.reLaunch()的區(qū)別?
6. 如果需要用戶授權(quán),用戶選擇拒絕授權(quán),此時(shí)應(yīng)該如何處理?" >6. 如果需要用戶授權(quán),用戶選擇拒絕授權(quán),此時(shí)應(yīng)該如何處理?
wx.getUserInfo(OBJECT)
7. 你平時(shí)封裝可以復(fù)用的方法嗎?你會(huì)把可以復(fù)用的方法寫在哪個(gè)文件里?" >7. 你平時(shí)封裝可以復(fù)用的方法嗎?你會(huì)把可以復(fù)用的方法寫在哪個(gè)文件里?
8. 分析下小程序的優(yōu)劣勢(shì)?" >8. 分析下小程序的優(yōu)劣勢(shì)?
9. 設(shè)置值到頁(yè)面暫存區(qū)(即data)里面的方法有幾種?分別是什么?有什么區(qū)別?" >9. 設(shè)置值到頁(yè)面暫存區(qū)(即data)里面的方法有幾種?分別是什么?有什么區(qū)別?
微信小程序--data的賦值與取值" >微信小程序--data的賦值與取值
10. 如何檢測(cè)用戶的微信版本是否支持某項(xiàng)功能?" >10. 如何檢測(cè)用戶的微信版本是否支持某項(xiàng)功能?
11. 如何分包加載?分包加載的優(yōu)勢(shì)在哪?" >11. 如何分包加載?分包加載的優(yōu)勢(shì)在哪?
12. 在你開發(fā)小程序的過(guò)程中遇到過(guò)什么坑? 你是怎么解決的?" >12. 在你開發(fā)小程序的過(guò)程中遇到過(guò)什么坑? 你是怎么解決的?
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

通過(guò)使用data - xxxx 的方法標(biāo)識(shí)來(lái)傳值

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

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

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

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

微信小程序如何跨頁(yè)面獲取值?

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

在跳轉(zhuǎn)后的js頁(yè)面,接收傳遞過(guò)來(lái)的數(shù)據(jù)detail.js

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

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

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

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

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

1,在wxml頁(yè)面中:

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

2,在js頁(yè)面中:

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

3,如果上述跳轉(zhuǎn)遇到跳轉(zhuǎn)失敗或無(wú)效的問(wèn)題,請(qǐng)?jiān)L問(wèn)下面鏈接:

wx.navigateTo/wx.redirectTo 無(wú)效

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

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

先看看這個(gè)接口的官方文檔:

wx.getUserInfo(OBJECT)

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

OBJECT參數(shù)說(shuō)明:

參數(shù)名

類型

必填

說(shuō)明

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)用成功、失敗都會(huì)執(zhí)行)

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

我們就是要在用戶點(diǎn)擊拒絕的時(shí)候,彈出提示框,提示用戶以提升用戶體驗(yàn)。像下面這樣的。

用具體代碼實(shí)現(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;您點(diǎn)擊了拒絕授權(quán),將無(wú)法正常使用******的功能體驗(yàn)。請(qǐng)10分鐘后再次點(diǎn)擊授權(quán),或者刪除小程序重新進(jìn)入。&#39;,
success: function (res) {
if (res.confirm) {
console.log(&#39;用戶點(diǎn)擊確定&#39;)
}
}
})
}
})


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

第一種思路:

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

wx.getUserInfo({
success: function (resuser) {
let userInfo = resuser.userInfo
that.healthApi.login(code, userInfo).then(logindata => {   // 這里將微信的請(qǐng)求封裝成Promiese 風(fēng)格
if (logindata.code === 0) {
var sessionId = logindata.data// 調(diào)用微信wechat.setStorage將換回來(lái)的 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;您點(diǎn)擊了拒絕授權(quán),將無(wú)法正常使用*****的功能體驗(yàn)。請(qǐng)10分鐘后再次點(diǎn)擊授權(quán),或者刪除小程序重新進(jìn)入。&#39;,
success: function (res) {
if (res.confirm) {
console.log(&#39;用戶點(diǎn)擊確定&#39;)
}
}
})
}
})


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

第二種思路:

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

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

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

官方文檔是這樣解釋的:

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

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

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

參數(shù)

類型

說(shuō)明

userInfo

OBJECT

用戶信息對(duì)象,不包含 openid 等敏感信息

rawData

String

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

signature

String

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

encryptedData

String

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

iv

String

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

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

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

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

applyIn: function applyIn() {
if (wx.getStorageSync(&#39;sessionId&#39;)) {  // 根據(jù)儲(chǔ)存的sessionId 進(jìn)行驗(yà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;您點(diǎn)擊了拒絕授權(quán),無(wú)法使用此功能。&#39;,
success: function (res) {
if (res.confirm) {
console.log(&#39;用戶點(diǎn)擊確定&#39;)
}
}
})
}


效果像這樣:

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

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

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

寫在html文件里有什么優(yōu)點(diǎn)嗎?
獨(dú)立出來(lái)會(huì)有什么問(wèn)題嗎?尤其是載入頁(yè)面的時(shí)候,應(yīng)該會(huì)多發(fā)很多http請(qǐng)求吧,會(huì)不會(huì)造成加載變慢?

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

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

優(yōu)勢(shì):

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

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

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

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

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

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

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

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

劣勢(shì):

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

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

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

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

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

6)小程序升級(jí)問(wèn)題,官方文檔說(shuō)會(huì)自動(dòng)更新,實(shí)際情況往往是要先把原來(lái)的小程序刪除掉,重新搜索添加,才能加載最新版本;

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

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

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

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

1. 使用QueryString變量
QueryString是一種非常簡(jiǎn)單的傳值方式,他可以將傳送的值顯示在瀏覽器的地址欄中。如果是傳遞一個(gè)或多個(gè)安全性要求不高或是結(jié)構(gòu)簡(jiǎn)單的數(shù)值時(shí),可以使用這個(gè)方法。但是對(duì)于傳遞數(shù)組或?qū)ο蟮脑?,就不能用這個(gè)方法了。下面是一個(gè)例子:
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 對(duì)象變量
Application對(duì)象的作用范圍是整個(gè)全局,也就是說(shuō)對(duì)所有用戶都有效。其常用的方法用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變量
想必這個(gè)肯定是大家使用中最常見的用法了,其操作與Application類似,作用于用戶個(gè)人,所以,過(guò)量的存儲(chǔ)會(huì)導(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對(duì)象變量
這個(gè)也是大家常使用的方法,與Session一樣,其是什對(duì)每一個(gè)用戶而言的,但是有個(gè)本質(zhì)的區(qū)別,即Cookie是存放在客戶端的,而session是存放在服務(wù)器端的。而且Cookie的使用要配合ASP.NET內(nèi)置對(duì)象Request來(lái)使用。

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方法
這個(gè)才可以說(shuō)是面象對(duì)象開發(fā)所使用的方法,其使用Server.Transfer方法把流程從當(dāng)前頁(yè)面引導(dǎo)到另一個(gè)頁(yè)面中,新的頁(yè)面使用前一個(gè)頁(yè)面的應(yīng)答流,所以這個(gè)方法是完全面象對(duì)象的,簡(jiǎn)潔有效。
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; //實(shí)例a窗體 
 newWeb = (source)Context.Handler; 
 string name; 
 name = newWeb.Name; 
}


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

通過(guò)小程序官方文檔可知:

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

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

· 頁(yè)面js文件中這么寫:

Page({
  data: {
    message: &#39;Hello MINA!&#39;
  }
})
· wxml中這么寫:
<view> {{ message }} </view>
· 如果該數(shù)據(jù)在操作過(guò)程中發(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. 如何檢測(cè)用戶的微信版本是否支持某項(xiàng)功能?

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


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)勢(shì)在哪?

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

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

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

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

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

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

{
  "pages":[
      //這是首頁(yè)面
    "pages/welcome/welcome"
  ]}


此時(shí)就會(huì)報(bào)錯(cuò)


2.在json文件中沒有寫內(nèi)容的時(shí)候也要加一對(duì)大括號(hào){ },不然的話也會(huì)報(bào)錯(cuò)

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

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


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

注意:這是錯(cuò)誤的寫法

{
  "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ū)別,這次主要說(shuō)一下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)一個(gè)父元素里面有多個(gè)子元素,需要把幾個(gè)子元素水平對(duì)齊,并且每個(gè)子元素都垂直劇中的時(shí)候,對(duì)每一個(gè)子元素進(jìn)行設(shè)置 vertical-align: middle?
③height: 40rpx; line-height: 40rpx;可以對(duì)文本進(jìn)行垂直居中

相關(guān)免費(fèi)學(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