消除红色图表未找到的警告和删除views下多余的vue文件
This commit is contained in:
@@ -18,7 +18,8 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
myChart: null,
|
||||
resizeHandler: null // 窗口resize事件处理器
|
||||
resizeHandler: null, // 窗口resize事件处理器
|
||||
isMounted: false // 图表挂载标志,避免过早执行
|
||||
};
|
||||
},
|
||||
props: {
|
||||
@@ -39,6 +40,7 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.isMounted = true;
|
||||
this.$nextTick(() => this.updateChart());
|
||||
// 注册窗口resize事件,使用稳定的引用以便后续移除
|
||||
this.resizeHandler = () => {
|
||||
@@ -51,17 +53,18 @@ export default {
|
||||
watch: {
|
||||
detailData: {
|
||||
handler() {
|
||||
if (!this.isMounted) return;
|
||||
this.updateChart();
|
||||
},
|
||||
deep: true,
|
||||
immediate: true
|
||||
deep: true
|
||||
// 移除 immediate: true,由 mounted 中的 updateChart() 处理初始化
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
updateChart() {
|
||||
const chartDom = this.$refs[this.refName];
|
||||
if (!chartDom) {
|
||||
console.error('图表容器未找到!');
|
||||
if (process.env.NODE_ENV === 'development') console.warn('图表容器未找到!');
|
||||
return;
|
||||
}
|
||||
console.log('this.detailData', this.detailData);
|
||||
|
||||
Reference in New Issue
Block a user