<template>
<view class="content">
<button @click="chooseVideo">chooseVideo</button>
<button open-type="uploadDouyinVideo" id="1" data-hello="world">uploadDouyinVideo</button>
</view>
</template>
<script>
let videoPath = ''
export default {
data() {
return {
videoPath: '',
}
},
onLoad() {},
onUploadDouyinVideo: uploadOptions => {
console.log('onUploadDouyinVideoOptions: ', uploadOptions)
// 返回值(文档中称之为 uploadParams)将被当作发布参数传入视频发布器,发布视频
return {
videoPath,
stickersConfig: {
text: [
{
text: '这是文字贴图',
color: '#ffffff',
fontSize: 28,
scale: 1,
x: 0.5,
y: 0.5,
},
],
},
success(callback) {
// 只有当发布成功且挂载成功时,success callback 才会有 videoId
console.log('success: ', callback)
},
fail(callback) {
console.log('fail: ', callback)
},
complete(callback) {
console.log('complete: ', callback)
},
}
},
methods: {
chooseVideo() {
tt.chooseVideo({
sourceType: ['album', 'camera'],
compressed: true,
success: res => {
this.videoPath = res.tempFilePath
videoPath = res.tempFilePath
},
fail: err => {
const errType = err.errMsg.includes('chooseVideo:fail cancel') ? '取消选择' : '选择失败'
tt.showModal({
title: errType,
content: err.errMsg,
showCancel: false,
})
},
})
},
},
}
</script>
<style lang="scss">
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>

- 发布:2022-08-11 17:52
- 更新:2023-11-08 10:24
- 阅读:1916
产品分类: uniapp/小程序/字节跳动
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: 12.5
第三方开发者工具版本号: 21.9.0
基础库版本号: 2.65.0
项目创建方式: CLI
CLI版本号: 2.0.1-35320220729001
示例代码:
操作步骤:
- ‘script’中定义onUploadDouyinVideo
- ‘template’中<button open-type="uploadDouyinVideo" id="1" data-hello="world">uploadDouyinVideo</button>进行触发
- ‘script’中定义onUploadDouyinVideo
- ‘template’中<button open-type="uploadDouyinVideo" id="1" data-hello="world">uploadDouyinVideo</button>进行触发
预期结果:
onUploadDouyinVideo 方法被调用
onUploadDouyinVideo 方法被调用
实际结果:
onUploadDouyinVideo 方法未被调用
onUploadDouyinVideo 方法未被调用
bug描述:
抖音小程序“发布抖音视频”功能无法触发“onUploadDouyinVideo 钩子”
该钩子必须在Page中定义,无法把原生小程序的代码变成小程序组件进行调用。

目前暂未支持 onUploadDouyinVideo,可自行绑定该方法到页面实例,示例:
onReady(){
this.$mp.page.onUploadDouyinVideo = function(uploadOptions) {
console.log('onUploadDouyinVideoOptions: ', uploadOptions)
}
}
-
-
-
-
回复 DCloud_UNI_WZF: 好的谢谢。
onReady(() => {
const thisPage = getCurrentPages()[0]
thisPage.onUploadDouyinVideo = (uploadOptions) => {
console.log('onUploadDouyinVideoOptions: ', uploadOptions)
return {
videoPath: videoSrc.value,
titleConfig: { title: '测试' },
success(res) {
console.log(res)
},
fail(err) {
console.log(err)
}
}
}
})
这种写法可以用2023-02-16 10:42
-
-

onReady(){
this.$mp.page.onUploadDouyinVideo = function(uploadOptions) {
console.log('onUploadDouyinVideoOptions: ', uploadOptions)
}
}请问这个是怎么解决问题的 没有看懂
-
-
回复 DCloud_UNI_WZF: <template>
<view class="content">
<button @click="chooseVideo">chooseVideo</button>
<button open-type="uploadDouyinVideo" id="1" data-hello="world">uploadDouyinVideo</button>
</view>
</template>
<script>
let videoPath = ''
export default {
data() {
return {
videoPath: '',
}
},
onReady(){
// console.log(this.$mp.page)
this.$mp.page.onUploadDouyinVideo = function(uploadOptions) {
console.log('onUploadDouyinVideoOptions: ', uploadOptions)
}
},
onLoad() {},
onUploadDouyinVideo: uploadOptions => {
console.log('onUploadDouyinVideoOptions: ', uploadOptions)
// 返回值(文档中称之为 uploadParams)将被当作发布参数传入视频发布器,发布视频
return {
videoPath,
stickersConfig: {
text: [
{
text: '这是文字贴图',
color: '#ffffff',
fontSize: 28,
scale: 1,
x: 0.5,
y: 0.5,
},
],
},
success(callback) {
// 只有当发布成功且挂载成功时,success callback 才会有 videoId
console.log('success: ', callback)
},
fail(callback) {
console.log('fail: ', callback)
},
complete(callback) {
console.log('complete: ', callback)
},
}
},
methods: {
chooseVideo() {
tt.chooseVideo({
sourceType: ['album', 'camera'],
compressed: true,
success: res => {
this.videoPath = res.tempFilePath
videoPath = res.tempFilePath
console.log(this.videoPath)
},
fail: err => {
const errType = err.errMsg.includes('chooseVideo:fail cancel') ? '取消选择' : '选择失败'
tt.showModal({
title: errType,
content: err.errMsg,
showCancel: false,
})
},
})
},
},
}
</script>
<style lang="scss">
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>
真机调试第二个按钮不反应 控制台什么也不打印2022-08-18 11:34
-
-
-
-
-

语文数学天才 - 做最顺手的nvue组件库与工具集
@DCloud_UNI_WZF vue3下没有开放 onUploadDouyinVideo 钩子。
-
-
回复 DCloud_UNI_WZF: import {onLoad, onShareAppMessage} from '@dcloudio/uni-app' 像这样。
2023-02-28 17:41
booboom (作者)
点赞
2022-09-02 15:41