Skip to content

Commit 0acb7b2

Browse files
committed
vibe docs
1 parent 9c2f431 commit 0acb7b2

File tree

2 files changed

+115
-3
lines changed

2 files changed

+115
-3
lines changed

README.md

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ See more examples [here](https://github.com/ecomfe/vue-echarts/tree/main/demo).
155155

156156
ECharts' universal interface. Modifying this prop will trigger ECharts' `setOption` method. Read more [here →](https://echarts.apache.org/en/option.html)
157157

158-
> 💡 When `update-options` is not specified, `notMerge: false` will be specified by default when the `setOption` method is called if the `option` object is modified directly and the reference remains unchanged; otherwise, if a new reference is bound to `option`, ` notMerge: true` will be specified.
158+
> [!TIP]
159+
> When `update-options` is not specified, `notMerge: false` will be specified by default when the `setOption` method is called if the `option` object is modified directly and the reference remains unchanged; otherwise, if a new reference is bound to `option`, ` notMerge: true` will be specified.
159160
160161
- `update-options: object`
161162

@@ -195,8 +196,7 @@ You can bind events with Vue's `v-on` directive.
195196
</template>
196197
```
197198

198-
> **Note**
199-
>
199+
> [!NOTE]
200200
> Only the `.once` event modifier is supported as other modifiers are tightly coupled with the DOM event system.
201201
202202
Vue-ECharts support the following events:
@@ -331,6 +331,62 @@ export default {
331331
- `clear` [](https://echarts.apache.org/en/api.html#echartsInstance.clear)
332332
- `dispose` [](https://echarts.apache.org/en/api.html#echartsInstance.dispose)
333333

334+
### Slots
335+
336+
Vue-ECharts allows you to define ECharts option's `tooltip.formatter` callbacks via Vue slots instead of defining them in your `option` object. This simplifies custom tooltip rendering using familiar Vue templating.
337+
338+
**Slot Naming Convention**
339+
340+
- Slot names begin with `tooltip`, followed by hyphen-separated path segments to the target formatter.
341+
- Each segment corresponds to an `option` property name or an array index (for arrays, use the numeric index).
342+
- The constructed slot name maps directly to the nested `formatter` it overrides.
343+
344+
**Example mappings**:
345+
346+
- `tooltip``option.tooltip.formatter`
347+
- `tooltip-baseOption``option.baseOption.tooltip.formatter`
348+
- `tooltip-xAxis-1``option.xAxis[1].tooltip.formatter`
349+
- `tooltip-series-2-data-4``option.series[2].data[4].tooltip.formatter`
350+
351+
<details>
352+
<summary>Usage</summary>
353+
354+
```vue
355+
<template>
356+
<v-chart :option="chartOptions">
357+
<!-- Override global tooltip.formatter -->
358+
<template #tooltip="{ params }">
359+
<table>
360+
<tr>
361+
<th>Series</th>
362+
<th>Value</th>
363+
</tr>
364+
<tr v-for="(s, i) in params" :key="i">
365+
<td>{{ s.seriesName }}</td>
366+
<td>{{ s.data }}</td>
367+
</tr>
368+
</table>
369+
</template>
370+
371+
<!-- Override tooltip on xAxis -->
372+
<template #tooltip-xAxis="{ params }">
373+
<div>X-Axis : {{ params.value }}</div>
374+
</template>
375+
</v-chart>
376+
</template>
377+
```
378+
379+
[Example→](https://vue-echarts.dev/#line)
380+
381+
</details>
382+
383+
#### Slot Props
384+
385+
- `params`: The first argument passed to the original [`tooltip.formatter`](https://echarts.apache.org/en/option.html#tooltip.formatter) callback.
386+
387+
> [!NOTE]
388+
> Slots take precedence over any `tooltip.formatter` defined in `props.option`. If a matching slot is present, the slot's content will render instead of using `option`'s formatter.
389+
334390
### Static Methods
335391

336392
Static methods can be accessed from [`echarts` itself](https://echarts.apache.org/en/api.html#echarts).

README.zh-Hans.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,62 @@ export default {
331331
- `clear` [](https://echarts.apache.org/zh/api.html#echartsInstance.clear)
332332
- `dispose` [](https://echarts.apache.org/zh/api.html#echartsInstance.dispose)
333333

334+
### 插槽(Slots)
335+
336+
Vue-ECharts 允许你通过 Vue 插槽来定义 ECharts 配置中的 `tooltip.formatter` 回调,而无需在 `option` 对象中定义它们。这简化了自定义提示框的渲染,让你可以用熟悉的 Vue 模板语法来编写。
337+
338+
**插槽命名约定**
339+
340+
- 插槽名称以 `tooltip` 开头,后面跟随用连字符分隔的路径片段,用于定位要覆盖的 `formatter`
341+
- 每个片段对应 `option` 对象的属性名或数组索引(数组索引使用数字形式)。
342+
- 拼接后的插槽名称直接映射到要覆盖的嵌套 `formatter`
343+
344+
**示例映射**
345+
346+
- `tooltip``option.tooltip.formatter`
347+
- `tooltip-baseOption``option.baseOption.tooltip.formatter`
348+
- `tooltip-xAxis-1``option.xAxis[1].tooltip.formatter`
349+
- `tooltip-series-2-data-4``option.series[2].data[4].tooltip.formatter`
350+
351+
<details>
352+
<summary>用法示例</summary>
353+
354+
```vue
355+
<template>
356+
<v-chart :option="chartOptions">
357+
<!-- 覆盖全局 tooltip.formatter -->
358+
<template #tooltip="{ params }">
359+
<table>
360+
<tr>
361+
<th>系列名称</th>
362+
<th>数值</th>
363+
</tr>
364+
<tr v-for="(item, idx) in params" :key="idx">
365+
<td>{{ item.seriesName }}</td>
366+
<td>{{ item.data }}</td>
367+
</tr>
368+
</table>
369+
</template>
370+
371+
<!-- 覆盖x轴 tooltip.formatter -->
372+
<template #tooltip-xAxis="{ params }">
373+
<div>X 轴: {{ params.value }}</div>
374+
</template>
375+
</v-chart>
376+
</template>
377+
```
378+
379+
[Example→](https://vue-echarts.dev/#line)
380+
381+
</details>
382+
383+
#### 插槽Props
384+
385+
- `params`[`tooltip.formatter`](https://echarts.apache.org/zh/option.html#tooltip.formatter) 回调的第一个参数。
386+
387+
> [!NOTE]
388+
> 插槽内容会优先于 `props.option` 中对应的 `tooltip.formatter` 渲染,如果两者同时存在。
389+
334390
### 静态方法
335391

336392
静态方法请直接通过 [`echarts` 本身](https://echarts.apache.org/zh/api.html#echarts)进行调用。

0 commit comments

Comments
 (0)