vue3.0 Ref never 类型 , 用的是 typescript
下面我给 option.value.series[0]['data']
赋值的时候报错, number 类型无法赋值给 nerve 类型, 想知道应该怎么解决呢
const option = ref({ title: {
text: "Traffic Sources",
left: "center"
},
tooltip: {
trigger: "item",
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
legend: {
orient: "vertical",
left: "left",
data: ["Direct", "Email", "Ad Networks", "Video Ads", "Search Engines"]
},
series: [
{
name: "Traffic Sources",
type: "pie",
radius: "55%",
center: ["50%", "60%"],
data: [],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: "rgba(0, 0, 0, 0.5)"
}
}
}
]
});
option.value.series[0]['data'] =
[{ value: 335, name: "Direct" },
{ value: 310, name: "Email" },
{ value: 234, name: "Ad Networks" },
{ value: 135, name: "Video Ads" },
{ value: 1548, name: "Search Engines" }]
回答:
默认对象属性值空数组类型推断结果是 never[] , 加上类型断言即可
data: [] as { value: number; name: string }[],
以上是 vue3.0 Ref never 类型 , 用的是 typescript 的全部内容, 来源链接: utcz.com/p/937185.html