I have a vue 3 component. The relevant script code below;
<script>
/* eslint-disable */
export default {
name: "BarExample",
data: dataInitialisation,
methods: {
updateChart,
}
};
function dataInitialisation()
{
return {
chartOptions: {
plotOptions: {
bar: {
horizontal: true
}
},
xaxis: {
//categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999],
categories: [1991, 1992],
}
},
series: [
{
name: "series-1",
data: [30, 40],
}
]
};
}
</script>
The above code works fine.
However, if I were to modify the function dataInitialisation() code into this;
function dataInitialisation()
{
init_data = {
chartOptions: {
plotOptions: {
bar: {
horizontal: true
}
},
xaxis: {
//categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999],
categories: [1991, 1992],
}
},
series: [
{
name: "series-1",
data: [30, 40],
}
]
};
return init_data;
}
With the function above, the vue website turned blank and no error message appeared. What is wrong? Both functions look pretty much the same to me.
EDIT:
I noticed another strange behaviour. I added a meaningless line x=2 to the function and this caused the website to go blank too.
function dataInitialisation()
{
x = 2; //meaningless line caused website to go blank
return {
chartOptions: {
plotOptions: {
bar: {
horizontal: true
}
},
xaxis: {
//categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999],
categories: [1991, 1992],
}
},
series: [
{
name: "series-1",
data: [30, 40],
}
]
};
}
I will answer my own question. I got the answer thanks to @3limin4t0r in the comment section.
I made a rookie mistake. I forgot the let in front of the variable init_data. There was no error message in javascript.
function dataInitialisation() {
let init_data = {
chartOptions: {
plotOptions: {
bar: {
horizontal: true,
},
},
xaxis: {
//categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999],
categories: [1991, 1992],
},
},
series: [
{
name: "series-1",
data: [30, 40],
},
],
};
return init_data;
}