#### 注意事項(xiàng)
1. 一個(gè)文件只能創(chuàng)建一個(gè)組件;**子組件標(biāo)簽首字母需大寫(xiě)**;
2. 更新數(shù)據(jù)只能使用 setData(異步操作),第二個(gè)參數(shù)選填,可以拿到更新后的數(shù)據(jù);
3. 布局單位使用 rpx,750 設(shè)計(jì)稿是多少就填多少;
4. 已對(duì) loading、error 進(jìn)行封裝,使用時(shí)只需在 temp 標(biāo)簽內(nèi)正常布局;
5. class 使用 className;
6. 變量統(tǒng)一包裹在{}中;
7. 在綁定需要手動(dòng)觸發(fā)的事件中,只能在函數(shù)里編寫(xiě),這種寫(xiě)法會(huì)默認(rèn)執(zhí)行一次;
? ```
? <View onClick={isFlag=true}></View>
? ```
但在 jsx 中使用匿名函數(shù)會(huì)占用大量?jī)?nèi)存空間,所以盡量不要使用匿名函數(shù);
8. 在給子組件傳遞函數(shù)時(shí),函數(shù)需用 bind 綁定 this。子組件在事件里給父組件傳遞參數(shù)時(shí),用 bind(this);
9. 給子組件傳遞 jsx 代碼時(shí),只能用**renderHeader**、**renderFooter**;
10. 引用本地圖片的時(shí)候,只能使用以下方式;
? ? ```
? ? import errorImage from './images/icon_error.png'
? ? ```
11. 上拉加載用**onReachBottom** () {} 沒(méi)效果,需要用箭頭函數(shù)。所以函數(shù)統(tǒng)一使用箭頭函數(shù);
12. 給 input 做雙向數(shù)據(jù)綁定時(shí),使用 e.detail.value 賦值;
13. **添加一個(gè)新組件之后頁(yè)面不顯示,終端也沒(méi)報(bào)錯(cuò),重啟終端解決;**
14. 列表添加無(wú)數(shù)據(jù)判斷時(shí),需要使用一個(gè)狀態(tài)傳至列表,不能直接根據(jù) length 判斷。因?yàn)闀簾o(wú)數(shù)據(jù)的樣式會(huì)一閃,然后才是列表數(shù)據(jù)。
15. 上傳圖片需要指定**header**的**centent-type**,不然 ios 手機(jī)有兼容問(wèn)題;
16. render 渲染中,如果一個(gè)對(duì)象有一個(gè)字段是數(shù)組,做容錯(cuò)處理時(shí),只需判斷該字段是否存在,不必加 length 的判斷,不然偶爾 length 會(huì)拿不到值。如:
? ? ```
? ? {item.creditSaleInfo && (
? ? ? <View className='ul'>
? ? ? ? {item.creditSaleInfo.map((v, i) => {
? ? ? ? ? return (
? ? ? ? ? ? <View className='li' key={v.id + i}>
? ? ? ? ? ? ? {v}
? ? ? ? ? ? </View>
? ? ? ? ? );
? ? ? ? })}
? ? ? </View>
? ? )}
? ? ```
#### 控制臺(tái)常見(jiàn)報(bào)錯(cuò):
- Uncaught TypeError: e.trim is not a function
? `解決:標(biāo)簽的className不能為空`
- Uncaught TypeError: Cannot read property 'apply' of undefined
? ```
? 解決:(1)給子組件傳遞事件代理程序時(shí),需給props指定默認(rèn)值
? ? ? (2)dom中調(diào)用了js未定義的方法
? ```
#### 命令行常見(jiàn)報(bào)錯(cuò):
- sh: taro: command not found
? `解決:執(zhí)行 sudo npm i -g @tarojs/cli --unsafe-perm=true --allow-root`
- TypeError [ERR_INVALID_ARG_TYPE]: The "to" argument must be of type string. Received type object
? `解決:把組件的文件夾改個(gè)名字就ok了。原因未知`
- const anonymousState\_\_temp = ;
? `解決:在return與render之間,給子組件傳遞dom的內(nèi)容中存在 {/* <!-- --> */}注釋?zhuān)籤
- Cannot read property 'css' of undefined
? ```
? 解決:(1)缺少Sass環(huán)境
? ? ? (2)Sass文件里缺少引用資源
? ```