1***@qq.com
1***@qq.com
  • 发布:2024-06-24 10:23
  • 更新:2024-06-24 10:23
  • 阅读:21

在微信小程序中, getImage()的返回结果是undefined

分类:uni-app

getImage()的结果是undefined

<template> <view class="charts-box-line" @click="getImg"> <qiun-data-charts ref="myBar" type="column" opts="optsBar" chartData="chartData" canvas2d="false" canvasId="CWRKlqxcHcxAUOzKCwMuHfNIgmIGdDQvfsfefasdfa" />
</view>
</template>

<script setup lang="ts">
import { onMounted, ref, nextTick } from 'vue'

const myBar = ref(null)
const chartData = ref({})
const optsBar = ref({
// color: ['#FBD091', '#ff0000', '#FAC858', '#EE6666', '#73C0DE', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],
padding: [0, 0, 0, 0],
enableScroll: false,
legend: {
show: false,
},
xAxis: {
disableGrid: true,
fontSize: 10,
title: '领先度',
},
yAxis: {
disabled: true,
disableGrid: true,
data: [
{
min: 0,
max: 50,
},
],
},
extra: {
column: {
type: 'group',
width: 20,
activeBgColor: '#000000',
activeBgOpacity: 0.08,
linearType: 'custom',
seriesGap: 5,
linearOpacity: 0.5,
barBorderCircle: true,
customColor: ['#FBCF91', '#FF9600', '#ff0000', '#bfa'],
},
},
})

onMounted(() => {
let res = {
categories: ['0%-60%', '61%-80%', '81%-90%', '91%-95%', '95%+'],
series: [
{
name: '人数',
data: [30, 35, 0, 10, 5],
},
{
name: '完成量',
data: [0, 0, 21, 0, 0],
},
],
}
chartData.value = JSON.parse(JSON.stringify(res))
// Ensure component is fully rendered before calling getImage
nextTick(() => {
if (myBar.value) {
console.log('Component is mounted:', myBar.value)
} else {
console.error('Component ref is not available')
}
})
})

function getImg() {
if (myBar.value) {
// Adding a delay to ensure the component is ready
setTimeout(() => {
const img = myBar.value.getImage()
console.log('img:', img)
}, 1000) // Adjust the delay as needed
} else {
console.error('myBar is not defined')
}
}
</script>

<style scoped lang="scss">
/ 请根据实际需求修改父元素尺寸,组件自动识别宽高 /
.charts-box-line {
width: 100%;
height: 400rpx;
}
</style>

2024-06-24 10:23 负责人:无 分享
已邀请:

要回复问题请先登录注册