-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build后无法获取echart的实例 #786
Comments
复现代码输出不了你截图的日志吧。 |
我仓库的代码复现不了吗 |
两次截图分别是打包前和打包后a的值 b的值是正常的,我就没截图 |
复现不了,你检查一下吧 |
可以复现啊 我准备了个在线的 |
直接运行 pnpm run preview |
mount 以前 ref 的 |
我这么写是没问题的,我打印的是ref而不是ref.value。而且就算是把log写在onMounted里,一样不行。 |
我试了一下在 preview 下取到组件实例是没有问题的,你不要看 console 打出来的内容,你试试实际调用实例上的方法看看。 |
确实是可以调用的,但是属性不可枚举还是有点问题的,在实现组件继承时,为了连expose一起继承,我可能会这么写 const chart = reactive({})
defineExpose(chart)
onMounted(()=>{
Object.assign(chart, chartInstance.value)
}) 这里当然可以改成 defineExpose({
chart: chartInstance
}) 但是这样写的话,每次调用包装后的组件都得多访问一层 包装前 const echart = ref()
onMounted(()=>{
echart.value.dispatchAction({})
}) 包装后 const echart = ref()
onMounted(()=>{
echart.value.chart.dispatchAction({})
}) 但是我包装组件的目的主要是为了全局覆写一些默认参数(比如 而且我不太清楚为何这个组件打包后所有的实例属性都不可枚举了,这使得某些依赖迭代器的用法都会在打包前后的表现不一致。比如 |
这个和 Vue ECharts 无关的,你搞一个只包含 Vue 的项目试一下,也是这样的。 |
你搞一个不是通过 |
请确认
您是如何将 Vue-ECharts 引入项目的?
通过 ES 模块 import
版本信息
问题详情
在dev环境下一切正常,但是build后,无法通过ref获取vueEchart的实例
以下是一个最小复现案例
https://github.com/Preyou/vue-project
分别运行dev,和build后的preview,打开控制台对比输出。
对于以下简单的测试代码
dev模式下正确拿到实例:
preview模式下的异常实例:
问题复现
https://github.com/Preyou/vue-project
The text was updated successfully, but these errors were encountered: