uni.createLivePusherContext中第二个参数是this,在setup里面不存在this,我参试传递getCurrentInstance()但是会报TypeError: Cannot read property 'meta' of undefined!那么请教一下如何在setup中正确使用uni.createLivePusherContext Api?
- 发布:2022-09-22 23:09
- 更新:2024-03-29 13:10
- 阅读:1601
同样的问题 null is not an object (evaluating 'vue.getCurrentInstance().proxy') __ERROR
<template>
<view class="container">
<button @click="qrBtn">QR扫描</button>
<view >
<live-pusher
class="livePusher"
id='livePusher'
ref="livePusher"
:url=url
mode="FHD"
muted="true"
min-bitrate="6000"
device-position="front"
@statechange="statechangeBtn"
></live-pusher>
</view>
</view>
</template>
<script setup>
import {reactive, ref,onMounted} from 'vue'
import {onReady} from '@dcloudio/uni-app'
const url = ref(null)
const statechangeBtn = (code,message) => {
console.log(code,'statechangeBtn')
console.log(message,'statechangeBtn')
}
onMounted(() => {
console.log('111')
this.context = uni.createLivePusherContext("livePusher", getCurrentInstance().proxy);
})
const qrBtn = () => {
uni.scanCode({
onlyFromCamera: true,
success: function (res) {
console.log('条码类型:' + res.scanType);
console.log('条码内容:' + res.result);
}
});
}
const barcode = ref(null);
推荐你去看这个代码:https://ext.dcloud.net.cn/plugin?id=12947,他用的就是setup,不股票这个live-pusher只有再nvue下能正常抓拍,vue不行。
我摘抄一部分他的源码吧。
<script setup lang="ts">
import { reactive, ref, onMounted, nextTick, getCurrentInstance } from 'vue';
const data = reactive({
_this: null,
snapshotsrc: null, //快照
})
onReady(() => {
data._this = getCurrentInstance().proxy;
data.livePusher = uni.createLivePusherContext('livePusher', data._this);
})
//抓拍
const snapshot = () => {
data.livePusher.snapshot({
success: e => {
console.log("拍照", e);
data.snapshotsrc = e.message.tempImagePath;
}
});
}
</script>
我用vue3写后报错[JS Framework] Failed to invoke the event handler of "click" on view (10):
TypeError: context.start is not a function
13:08:39.771 reportJSException >>>> exception function:WEEX_CALL_JAVASCRIPT, exception:JavaScript execute error!Uncaught TypeError: context.start is not a function
at start (/pages/called/called.nvue:96:17)
8***@qq.com
你好,请问创建地图组件实例的时候 uni.createMapContext(id,this) 中的this 再setup中 如何传呢? 我试了上面的getCurrentInstance().proxy 无效。
2023-03-27 17:21
DCloud_UNI_WZF
回复 8***@qq.com: 无效具体指什么,详细描述你的问题,如有必要,提供下测试工程
2023-03-28 10:58
d***@ohimy.com
我遇到了同样的问题,null is not an object (evaluating 'vue.getCurrentInstance().proxy') __ERROR,请问import {
getCurrentInstance
} from 'vue' 是这样用的吗?
2023-04-05 03:27
DCloud_UNI_WZF
回复 d***@ohimy.com: 附件提供下最简测试工程
2023-04-05 17:49