CHANX's Blog

vuePress-theme-reco CHANX    2019 - 2020
CHANX's Blog

Choose mode

  • dark
  • auto
  • light
主页
分类
  • 其他other
  • 前端front-end
  • 后端back-end
  • 笔记note
  • 随笔essay
标签
时间轴
关于我
每日AC
快速访问🎈
  • 洛谷 (opens new window)
  • Virtual Judge (opens new window)
  • LeetCode (opens new window)
  • Vue.js (opens new window)
  • Can I Use (opens new window)
  • Java SE API Documentation (opens new window)
  • Program Creek (opens new window)
  • Spring (opens new window)
  • Stackoverflow (opens new window)
  • Linux命令大全 (opens new window)
  • 编程语言排行榜 (opens new window)
GitHub (opens new window)
author-avatar

CHANX

37

Article

21

Tag

主页
分类
  • 其他other
  • 前端front-end
  • 后端back-end
  • 笔记note
  • 随笔essay
标签
时间轴
关于我
每日AC
快速访问🎈
  • 洛谷 (opens new window)
  • Virtual Judge (opens new window)
  • LeetCode (opens new window)
  • Vue.js (opens new window)
  • Can I Use (opens new window)
  • Java SE API Documentation (opens new window)
  • Program Creek (opens new window)
  • Spring (opens new window)
  • Stackoverflow (opens new window)
  • Linux命令大全 (opens new window)
  • 编程语言排行榜 (opens new window)
GitHub (opens new window)

微信小程序开发的坑

vuePress-theme-reco CHANX    2019 - 2020

微信小程序开发的坑

CHANX 2020-09-04 23:08:15 微信小程序

# Swiper高度自适应

swiper组件设置高度100%无法生效,这时需要通过手动获取屏幕的高度并给swiper设置

data:{
	swiperHeight: 0;
}
//监听页面加载
onLoad:function (option){
	const _this = this;
	wx.getSystemInfo({
		success:functioin(res) {
			const clientHeight = res.windowHeight;
			const clientWidth = res.windowWidth;
			const ratio = 750 / clientWidth;//计算为百分比
			const rpxHeight = ratio * clientHeight;
			_this.setData({
				_this.swiperHeight: rpxHeight;//将计算好的高度给定义好的值
      })
		}
 	})
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

将获取到的屏幕高度给swiper设置上

<swiper style="height:{{swiperHeight}}rpx;"><swiper/>
1

注意:style最后的rpx千万不能省略,否则不生效

# 小程序下载、预览文档

把文件下载到临时的缓存,然后再打开。需要注意上线的项目中文件地址需要https

onLoad: function(res){
  var url = '文件地址';
  wx.downloadFile({ //下载
    url: url,
    success: function(e){
      const filePath = e.tempFilePath; // 临时文件地址
      wx.openDocument({ // 预览
        filePath: filePath,
        success: function (ret) {
          console.log('打开文档成功')
        }
      })
    },
    fail: function(r){
      console.log(r)
    }
  })
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# 云开发中数据库的权限问题

需要注意不同的权限导致api获取数据为空

# 云函数中使用axios不能直接对返回值进行操作

解决方案:使用cheerio + utils

相关资料:cheerio (opens new window)

await axios.request({
  ...
}).then((res)=>{
  let data = eval (util.inspect(res.data));
  cookie = eval(util.inspect(res.headers["set-cookie"][0]));

  const $ = cheerio.load(data);
  $("#casLoginForm input").each((index,item)=>{
    //解析html
    ...
  })
})
    
1
2
3
4
5
6
7
8
9
10
11
12
13

# 解析并渲染Markdown

wxpraser-plugin使用 (opens new window)

在 GitHub 上编辑此页! (opens new window)
上次更新时间: 9/20/2020, 7:10:48 AM