nuxt使用vue-echarts第三方插件报错document is not defined
原因:
"document is not defined"错误通常出现在服务端渲染(SSR)环境中,因为vue-echarts在服务端没有document对象。
解决方法:
改成动态引入。
<template><componentv-if="VChart":is="VChart"/>
</template><script lang="ts" setup>
const VChart: any = ref(null);
onMounted(async () => {if (process.client) {const { default: VChartComponent } = await import("vue-echarts");VChart.value = VChartComponent;}
});
</script>