feat: 暴露方法给父组件,用于获取图表图片数据

This commit is contained in:
2025-12-11 17:57:20 +08:00
parent d164cd321c
commit 74eb51c52e
2 changed files with 38 additions and 0 deletions

View File

@ -161,6 +161,25 @@ const initChart = () => {
} }
}, 100); }, 100);
}; };
// 暴露方法给父组件,用于获取图表图片数据
defineExpose({
getChartImage: () => {
if (myChart.value) {
return myChart.value.getDataURL({
type: 'png',
pixelRatio: 2,
backgroundColor: '#fff'
});
}
return null;
},
resizeChart: () => {
if (myChart.value) {
myChart.value.resize();
}
}
});
</script> </script>
<style scoped> <style scoped>

View File

@ -190,6 +190,25 @@ watch([
], () => { ], () => {
initChart(); initChart();
}); });
// 暴露方法给父组件,用于获取图表图片数据
defineExpose({
getChartImage: () => {
if (chartInstance.value) {
return chartInstance.value.getDataURL({
type: 'png',
pixelRatio: 2,
backgroundColor: '#fff'
});
}
return null;
},
resizeChart: () => {
if (chartInstance.value) {
chartInstance.value.resize();
}
}
});
</script> </script>
<style scoped> <style scoped>
:deep(div) { :deep(div) {