uniapp实现app分享视频到微信
uniapp官方提供uni.share方法进行分享操作,有个参数为type,代表分享的文件类型,视频是type=4,但是实际上分享到微信的效果并不好,请看下图:
在这里推荐一个方法,使用type=0,设置href为视频路径,title为视频标题,summary为视频内容,imageUrl为视频封面图。title和summary可以二选一,但是为了美观,推荐两个一起或者使用summary,效果如下:
实际代码如下:
uni.share({
provider: "weixin",
scene: '', //参照官方文档,需要分享到的场景
href: this.href,
type: 0,
title: this.title,
summary: this.summary,
imageUrl: this.imageUrl,
success: function(res) {
uni.showToast({
title: '分享成功',
icon: 'none'
});
},
fail: function(err) {
uni.showToast({
title: '分享失败',
icon: 'none'
});
}
});