【发布时间】:2020-08-11 22:11:44
【问题描述】:
updateSeries 功能似乎不起作用。我不知道为什么它没有。 uChart() 函数确实被调用了。我有以下代码:
<template>
<div>
<Menu></Menu>
<h1> Our Home Website! </h1>
<apexchart ref="chart1" width="500" type="line" :options="options" :series="series"></apexchart>
</div>
从'./Menu'导入菜单 从'axios'导入axios
export default {
name: 'Home',
components: {
'Menu': Menu
},
data: function () {
return {
options: {
chart: {
height: 350,
type: 'bar',
id: 'chart'
},
dataLabels: {
enabled: false
},
series: [],
title: {
text: 'Ajax Example',
},
noData: {
text: 'Loading...'
}
}
}
},
mounted: function () {
this.uChart()
},
methods: {
uChart: function() {
axios
.get('http://my-json-server.typicode.com/apexcharts/apexcharts.js/yearly')
.then(function (response) {
this.$refs.chart1.updateSeries([{
name: 'Sales',
data: response.data
}])
});
console.log(this.$refs.chart1);
}
}
对图表的引用和 JSON 数据的链接一样有效。但图表仍处于“加载”状态: This is how it actually looks like on the website and the errors that I get
【问题讨论】:
-
TL;DR:
then参数是一个回调,应该是一个箭头。 -
是的,这有帮助。谢谢你。我将 then() 函数更改为以下语法: .then(response => {...
标签: vue.js web-applications apexcharts