最近一周在改造 公羊阅读? Taro 版本适配 h5 端,过程中改改补补,好不酸爽。 本文记录?遇到的问题,希望为有相同需求的哥们?节约点时间。 Taro 版本:1.3.9。 client_mobile_taro - github地址
解决跨域问题
h5 发请求会报跨域问题,需要使用代理转换请求。
编辑根目录下的 config/index.js 文件
h5: {
devServer: {
host: 'localhost',
port: 10086,
proxy: {
'/api/v1': {
target: 'http://localhost:8000', // 服务端地址
changeOrigin: true
}
}
},
}
- 代理前的请求:
http://localhost:10086/api/v1/user
- 代理后的请求:
http://localhost:8000/api/v1/user
样式单位
小程序里规定 1px = 2rpx,Taro 对于像素(px)有一套自己的规则。
在 Taro 里可以写 rpx 作为单位。
- Taro 代码转小程序代码:无缝转换为小程序单位;
- Taro 代码转 h5 代码:无法转换。
// taro
height: 10rpx;
// weapp
he