@antv/s2-vue
v2.0.0
Published
use S2 with vue
Downloads
637
Maintainers
Readme
数据驱动的多维分析表格 (Vue3 版本)
@antv/s2-vue
现已停止维护,由于精力投入有限,出于维护成本,包下载量等因素综合考虑,从2.0.0
正式版后不再继续更新,请基于@antv/s2
自行封装,或 fork 仓库进行二次开发社区版本。
📦 安装
$ pnpm add @antv/s2-vue
# yarn add @antv/s2-vue
# npm install @antv/s2-vue --save
🔨 使用
1. 数据准备
const s2DataConfig = {
fields: {
rows: ['province', 'city'],
columns: ['type', 'sub_type'],
values: ['number'],
},
meta: [
{
field: 'number',
name: '数量',
},
{
field: 'province',
name: '省份',
},
{
field: 'city',
name: '城市',
},
{
field: 'type',
name: '类别',
},
{
field: 'sub_type',
name: '子类别',
},
],
data: [
{
number: 7789,
province: '浙江省',
city: '杭州市',
type: '家具',
sub_type: '桌子',
},
{
number: 2367,
province: '浙江省',
city: '绍兴市',
type: '家具',
sub_type: '桌子',
},
{
number: 3877,
province: '浙江省',
city: '宁波市',
type: '家具',
sub_type: '桌子',
},
{
number: 4342,
province: '浙江省',
city: '舟山市',
type: '家具',
sub_type: '桌子',
},
{
number: 5343,
province: '浙江省',
city: '杭州市',
type: '家具',
sub_type: '沙发',
},
{
number: 632,
province: '浙江省',
city: '绍兴市',
type: '家具',
sub_type: '沙发',
},
{
number: 7234,
province: '浙江省',
city: '宁波市',
type: '家具',
sub_type: '沙发',
},
{
number: 834,
province: '浙江省',
city: '舟山市',
type: '家具',
sub_type: '沙发',
},
{
number: 945,
province: '浙江省',
city: '杭州市',
type: '办公用品',
sub_type: '笔',
},
{
number: 1304,
province: '浙江省',
city: '绍兴市',
type: '办公用品',
sub_type: '笔',
},
{
number: 1145,
province: '浙江省',
city: '宁波市',
type: '办公用品',
sub_type: '笔',
},
{
number: 1432,
province: '浙江省',
city: '舟山市',
type: '办公用品',
sub_type: '笔',
},
{
number: 1343,
province: '浙江省',
city: '杭州市',
type: '办公用品',
sub_type: '纸张',
},
{
number: 1354,
province: '浙江省',
city: '绍兴市',
type: '办公用品',
sub_type: '纸张',
},
{
number: 1523,
province: '浙江省',
city: '宁波市',
type: '办公用品',
sub_type: '纸张',
},
{
number: 1634,
province: '浙江省',
city: '舟山市',
type: '办公用品',
sub_type: '纸张',
},
{
number: 1723,
province: '四川省',
city: '成都市',
type: '家具',
sub_type: '桌子',
},
{
number: 1822,
province: '四川省',
city: '绵阳市',
type: '家具',
sub_type: '桌子',
},
{
number: 1943,
province: '四川省',
city: '南充市',
type: '家具',
sub_type: '桌子',
},
{
number: 2330,
province: '四川省',
city: '乐山市',
type: '家具',
sub_type: '桌子',
},
{
number: 2451,
province: '四川省',
city: '成都市',
type: '家具',
sub_type: '沙发',
},
{
number: 2244,
province: '四川省',
city: '绵阳市',
type: '家具',
sub_type: '沙发',
},
{
number: 2333,
province: '四川省',
city: '南充市',
type: '家具',
sub_type: '沙发',
},
{
number: 2445,
province: '四川省',
city: '乐山市',
type: '家具',
sub_type: '沙发',
},
{
number: 2335,
province: '四川省',
city: '成都市',
type: '办公用品',
sub_type: '笔',
},
{
number: 245,
province: '四川省',
city: '绵阳市',
type: '办公用品',
sub_type: '笔',
},
{
number: 2457,
province: '四川省',
city: '南充市',
type: '办公用品',
sub_type: '笔',
},
{
number: 2458,
province: '四川省',
city: '乐山市',
type: '办公用品',
sub_type: '笔',
},
{
number: 4004,
province: '四川省',
city: '成都市',
type: '办公用品',
sub_type: '纸张',
},
{
number: 3077,
province: '四川省',
city: '绵阳市',
type: '办公用品',
sub_type: '纸张',
},
{
number: 3551,
province: '四川省',
city: '南充市',
type: '办公用品',
sub_type: '纸张',
},
{
number: 352,
province: '四川省',
city: '乐山市',
type: '办公用品',
sub_type: '纸张',
},
],
};
const rawOptions: S2Options = {
width: 600,
height: 480,
};
2. 组件配置
// App.vue
<script lang="ts">
import type { S2DataConfig, S2Options } from '@antv/s2';
import { SheetComponent } from '@antv/s2-vue';
import { defineComponent, onMounted, reactive, shallowRef } from 'vue';
import "@antv/s2-vue/dist/s2-vue.min.css";
export default defineComponent({
setup() {
const s2 = shallowRef();
// dataCfg 数据字段较多,建议使用 shallow, 如果有数据更改直接替换整个对象
const dataCfg = shallowRef(s2DataConfig);
const options: S2Options = reactive(S2Options);
onMounted(() => {
console.log('s2 instance:', s2.value?.instance);
});
return {
s2,
dataCfg,
options,
};
},
components: {
SheetComponent,
},
});
</script>
<template>
<SheetComponent ref="s2" :dataCfg="dataCfg" :options="options" />
</template>
3. 渲染
import { createApp } from 'vue';
import App from './App.vue';
createApp(App).mount('#app');