[英]How to convert the following JavaScript logic using vuejs with ES6 standards
I have a JavaScript file, and I want the same logic to be implemented using Vuejs with ES6 standards.我有一个 JavaScript 文件,我希望使用具有 ES6 标准的 Vuejs 实现相同的逻辑。 I want to add this logic in "LineChart.vue" and then i will import it to my parent.vue in order to display charts.
我想在“LineChart.vue”中添加这个逻辑,然后我会将它导入到我的 parent.vue 中以显示图表。
As in vuejs there are lots of life cycle hook methods, as I'm new to vuejs I don't know to how implement this same logic in vuejs.和 vuejs 一样,有很多生命周期钩子方法,因为我是 vuejs 新手,我不知道如何在 vuejs 中实现相同的逻辑。 Please help me with this.
请帮我解决一下这个。
The code is here:代码在这里:
function chart_shot(type, id, interval) {
$.ajax({
type: "GET",
url: getApiUrl("find/" + type + "?interval=" + interval),
headers: {
"api_key": ''
},
cache: true,
timeout: 30,
dataType: "json",
success: function (data) {
var ctx = document.getElementById(id);
var highChart = [];
for(i = 0; i < data["date"].length; i++) {
highChart.push({
t: moment(data["date"][i], "X").toDate(),
y: data["challenges"][i]
})
}
if(my !== undefined) {
my.destroy();
}
my = new Chart(ctx, {
type: 'line',
data: {
datasets: [{
label: "challenges",
data: highChart,
}]
},
options: {
lineTension: 0,
maintainAspectRatio: false,
legend: {
display: false
},
scales: {
yAxes: [{
scaleLabel: {
display: false
},
ticks: {
beginAtZero: true,
callback: function (value, index, values) {
return value + '%';
}
}
}],
xAxes: [{
type: 'time',
time: {
unit: 'month'
},
scaleLabel: {
display: true,
labelString: ''
},
}]
}
}
});
}
});
} }
Please help me with this as I am new to vuejs I don't know effective way of writing this code in vuejs.请帮助我,因为我是 vuejs 的新手,我不知道在 vuejs 中编写此代码的有效方法。
And please do tell me in which file type it can be done, i mean in js or vue?请告诉我它可以在哪种文件类型中完成,我的意思是在 js 或 vue 中?
And how the written code can be used in other vue component.以及如何在其他 vue 组件中使用编写的代码。
https://codesandbox.io/s/dry-cache-ilesg https://codesandbox.io/s/dry-cache-ilesg
Here is a little demo for the VueJS app related to your question.这是与您的问题相关的 VueJS 应用程序的一个小演示。 Please check it out you will get some idea about how it's working.
请检查一下,您将对它的工作原理有所了解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.