feat: 暴露方法给父组件,用于获取图表图片数据
This commit is contained in:
@ -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>
|
||||||
|
|||||||
@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user