$默认为全局property,使用Vue.prototype. $xx声明的property是不想污染全局作用域,一些组件引入后会留一个实例property如echartimport echarts from 'echarts',留下echarts实例供我们调用。
使用vue.prototype. $echarts = echarts后,我们就能直接使用 $echarts避免重名
vue中$的使用
最新推荐文章于 2025-10-13 05:58:52 发布
在 Vue 应用中,通过 Vue.prototype.$echarts = echarts 的方式可以避免污染全局作用域,同时确保组件间不冲突地使用 ECharts 图表库。这种方式将 echarts 引入并绑定到 Vue 实例上,使得在组件内部可以直接通过 this.$echarts 访问和使用 ECharts 实例,方便快捷。
1530

被折叠的 条评论
为什么被折叠?



