2020年2月4日 uniapp开发踩坑记录

## 第一大坑

小程序不支持session 和 cookie 记录用户登录信息,小程序是通过先微信服务器再到我们服务器

解决办法:uni.setStorageSync()存储 header['Set-Cookie'] ;

下次请求中 header.Cookie 为已存储的cookie

```javascript

post(url, params) {
        let header = {}
        // #ifndef H5
        header.Cookie = uni.getStorageSync('sessionID');
        // #endif
        return new Promise((resolve, reject) => {
            // instance.post(url, psarams).then(r => {
            //     console.log(url)
            //     resolve(r.data);
            // })
            uni.request({
                url: helper.websiteUrl+url,
                data: params,
                method:'POST',
                header:header,
                success: (res) => {
                    console.log(res)
                    // #ifndef H5
                    if(res && res.header && res.header['Set-Cookie']){
                        uni.setStorageSync('sessionID',res.header['Set-Cookie'])
                    }
                    // #endif
                    resolve(res.data)
                },
                fail: () => {
                    
                }
            })
        })
    }

```

## 不算坑

Vuex 除了commit、dispatch 触发 mutations和action外,还能

import {
        mapState,
        mapMutations,
		mapActions
    } from 'vuex'
...
methods:{
    ...mapMutations(['balabala(函数名)'])
    ...mapActions(['balabala'])
}

这样可以把vuex中的对应函数暴露出来直接像普通函数一样调用

这是我急功近利的原因

## 第三坑

插件市场有个老哥做了《socket.io-client(uniapp版) 》

让我们在uniapp上也能用socket.io

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值