updateSeries函数似乎不起作用。我不明白为什么它不是这样。确实会调用uChart()函数。我有以下代码:
<template>
<div>
<Menu></Menu>
<h1> Our Home Website! </h1>
<apexchart ref="chart1" width="500" type="line" :options="options" :series="series"></apexchart>
</div>
import Menu from './Menu' import axios from '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
发布于 2020-04-30 16:22:21
正如埃斯特斯·弗拉斯克在他的评论中提到的那样。这个问题的答案是对"then“参数使用箭头语法,因为它是一个回调。因此,正确的函数如下所示:
methods: {
uChart: function() {
axios
.get('http://my-json-server.typicode.com/apexcharts/apexcharts.js/yearly')
.then(response => {
this.$refs.chart1.updateSeries([{
name: 'Sales',
data: response.data
}])
});
console.log(this.$refs.chart1);
}
}有关此主题的更多详细信息,请查看此问题的答案:How to access the correct this inside a callback?
https://stackoverflow.com/questions/61474411
复制相似问题