Giter VIP home page Giter VIP logo

Comments (13)

Justineo avatar Justineo commented on June 26, 2024

复现代码输出不了你截图的日志吧。

from vue-echarts.

Preyou avatar Preyou commented on June 26, 2024

复现代码输出不了你截图的日志吧。

我仓库的代码复现不了吗

from vue-echarts.

Preyou avatar Preyou commented on June 26, 2024

复现代码输出不了你截图的日志吧。

两次截图分别是打包前和打包后a的值

b的值是正常的,我就没截图

from vue-echarts.

Justineo avatar Justineo commented on June 26, 2024

我仓库的代码复现不了吗

复现不了,你检查一下吧

from vue-echarts.

Preyou avatar Preyou commented on June 26, 2024

我仓库的代码复现不了吗

复现不了,你检查一下吧

可以复现啊

image

我准备了个在线的
https://stackblitz.com/~/github.com/Preyou/vue-project?file=src/App.vue

from vue-echarts.

Preyou avatar Preyou commented on June 26, 2024

我仓库的代码复现不了吗

复现不了,你检查一下吧

可以复现啊

image

我准备了个在线的 https://stackblitz.com/~/github.com/Preyou/vue-project?file=src/App.vue

直接运行 pnpm run preview
再看控制台就可以发现,没有正确的获取实例

from vue-echarts.

Justineo avatar Justineo commented on June 26, 2024

mount 以前 ref 的 value 应该是 undefined 吧,你这么写如果能取到值那肯定是因为热更新导致的。这在生产环境肯定不对啊。

from vue-echarts.

Preyou avatar Preyou commented on June 26, 2024

mount 以前 ref 的 value 应该是 undefined 吧,你这么写如果能取到值那肯定是因为热更新导致的。这在生产环境肯定不对啊。

我这么写是没问题的,我打印的是ref而不是ref.value。而且就算是把log写在onMounted里,一样不行。

from vue-echarts.

Justineo avatar Justineo commented on June 26, 2024

我试了一下在 preview 下取到组件实例是没有问题的,你不要看 console 打出来的内容,你试试实际调用实例上的方法看看。

from vue-echarts.

Preyou avatar Preyou commented on June 26, 2024

我试了一下在 preview 下取到组件实例是没有问题的,你不要看 console 打出来的内容,你试试实际调用实例上的方法看看。

确实是可以调用的,但是属性不可枚举还是有点问题的,在实现组件继承时,为了连expose一起继承,我可能会这么写

const chart = reactive({})

defineExpose(chart)

onMounted(()=>{
  Object.assign(chart, chartInstance.value)
})

这里当然可以改成

defineExpose({
  chart: chartInstance
})

但是这样写的话,每次调用包装后的组件都得多访问一层chart

包装前

const echart = ref()

onMounted(()=>{
   echart.value.dispatchAction({})
})

包装后

const echart = ref()

onMounted(()=>{
   echart.value.chart.dispatchAction({})
})

但是我包装组件的目的主要是为了全局覆写一些默认参数(比如theme),避免每个调用的地方都要再写一遍。并不想改变原有组件的用法,以便其他开发人员可以在仅参考原有文档的基础上就能使用包装后的组件。

而且我不太清楚为何这个组件打包后所有的实例属性都不可枚举了,这使得某些依赖迭代器的用法都会在打包前后的表现不一致。比如for in...objObject.assignObject.keysObject.valuesObject.entries等,都将无法在打包后正确拿到属性。

from vue-echarts.

Justineo avatar Justineo commented on June 26, 2024

这个和 Vue ECharts 无关的,你搞一个只包含 Vue 的项目试一下,也是这样的。

from vue-echarts.

Preyou avatar Preyou commented on June 26, 2024

这个和 Vue ECharts 无关的,你搞一个只包含 Vue 的项目试一下,也是这样的。

我在示例里不是还打印了一个变量b吗,这个b就是正常可枚举的。

image

from vue-echarts.

Justineo avatar Justineo commented on June 26, 2024

你搞一个不是通过 defineExpose 定义的实例。

from vue-echarts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.