天天看点

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