【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))

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章