|
@@ -5,23 +5,33 @@ import * as echarts from 'echarts'
|
|
|
|
|
|
// 定义类型
|
|
// 定义类型
|
|
const PropsType = {
|
|
const PropsType = {
|
|
|
|
+ // 图表唯一 id
|
|
id: String,
|
|
id: String,
|
|
|
|
+ // 图表类名
|
|
className: {
|
|
className: {
|
|
type: String,
|
|
type: String,
|
|
default: 'chart'
|
|
default: 'chart'
|
|
},
|
|
},
|
|
|
|
+ // 图表宽度
|
|
width: {
|
|
width: {
|
|
type: String,
|
|
type: String,
|
|
require: true
|
|
require: true
|
|
},
|
|
},
|
|
|
|
+ // 图表高度
|
|
height: {
|
|
height: {
|
|
type: String,
|
|
type: String,
|
|
require: true
|
|
require: true
|
|
},
|
|
},
|
|
|
|
+ // 图表数据项
|
|
options: {
|
|
options: {
|
|
type: Object,
|
|
type: Object,
|
|
default: () => ({}),
|
|
default: () => ({}),
|
|
- require: true
|
|
|
|
|
|
+ require: true
|
|
|
|
+ },
|
|
|
|
+ // 手动触发更新标识,建议从 0 开始
|
|
|
|
+ updateFlag: {
|
|
|
|
+ type: Number,
|
|
|
|
+ default: 0,
|
|
}
|
|
}
|
|
} as const
|
|
} as const
|
|
|
|
|
|
@@ -34,7 +44,7 @@ export default defineComponent({
|
|
|
|
|
|
// 初始化echart
|
|
// 初始化echart
|
|
const initChart = () => {
|
|
const initChart = () => {
|
|
- chart.value.setOption(props.options, true)
|
|
|
|
|
|
+ chart.value.setOption(props.options)
|
|
}
|
|
}
|
|
|
|
|
|
// 生命周期
|
|
// 生命周期
|
|
@@ -61,6 +71,11 @@ export default defineComponent({
|
|
}
|
|
}
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+ // 手动触发图表渲染
|
|
|
|
+ watch(() => props.updateFlag, () => {
|
|
|
|
+ initChart()
|
|
|
|
+ })
|
|
|
|
+
|
|
return () => {
|
|
return () => {
|
|
const { id, className, height, width } = props
|
|
const { id, className, height, width } = props
|
|
return <div
|
|
return <div
|