天天看點

【uniapp踩坑系列】

1.uni.uploadFile成功後傳回參數問題

官方文檔裡面,傳回參數是 data, statusCode;其中data是string類型,是以我們需要轉換成JSON

success:(res) => {
			if(res.data){
		    	const data = JSON.parse(res.data)
				uni.setStorageSync('headUrl',data.data)
					}
							}
           

2. TypeError: Cannot set property 'xxx' of undefined

一種情況可能是:使用的是跟下面類似的名字函數,this 關鍵字是匿名函數。

是以把success回調函數改成箭頭函數就ok。即改成上面例子裡的箭頭函數

success:function(res){
				if(res.data){	
                      this.other = res.data
				}
				}
           

3.接口引入背景圖檔的寫法

寫法1:

<view class="top bg-gradual-blue" :style="{backgroundImage:`url(${bg})`}">
			
			<view class="flex padding-bottom justify-start margin-top">
				<view class="padding-top margin-left ">
					<view class="cu-avatar round xl" :style="{backgroundImage:`url(${photo})`}">
					</view>
				</view>
				
			</view>
		</view>
           

寫法2:

<view class="cu-avatar round" :style="[{backgroundImage:'url('+photo+')'}]"></view>
           

4.頁面帶參數跳轉,參數過長時的方法:

帶參頁:

const param = encodeURIComponent(JSON.stringify(e))
				uni.navigateTo({
					url:'../Square/activityDetail?param=' + param
				})
           

取參頁:

const data = JSON.parse(decodeURIComponent(options.param))