link959 link960 link961 link962 link963 link964 link965 link966 link967 link968 link969 link970 link971 link972 link973 link974 link975 link976 link977 link978 link979 link980 link981 link982 link983 link984 link985 link986 link987 link988 link989 link990 link991 link992 link993 link994 link995 link996 link997 link998 link999 link1000 link1001 link1002 link1003 link1004 link1005 link1006 link1007 link1008 link1009 link1010 link1011 link1012 link1013 link1014 link1015 link1016 link1017 link1018 link1019 link1020 link1021 link1022 link1023 link1024 link1025 link1026 link1027 link1028 link1029 link1030 link1031 link1032 link1033 link1034 link1035 link1036 link1037 link1038 link1039 link1040 link1041 link1042 link1043 link1044 link1045 link1046 link1047 link1048 link1049 link1050 link1051 link1052 link1053 link1054 link1055 link1056 link1057 link1058 link1059 link1060 link1061 link1062 link1063 link1064 link1065 link1066 link1067 link1068 link1069 link1070 link1071 link1072 link1073 link1074 link1075 link1076 link1077 link1078 link1079 link1080 link1081 link1082 link1083 link1084 link1085 link1086 link1087 link1088 link1089 link1090 link1091 link1092 link1093 link1094 link1095

[Vue.js] Axios.get call for years as value

when trying to get a json file from server. Endpoint has a year parameter with the current year number as value like so: ?year=2019. I also need to get a year before that and next year. So if someone enters data in the backend for 2018, 2019 or 2020 I should be able to retrieve it. The problem is that I cannot hard code the years since next year I would need 2019, 2020 and 2021 and so on :)

I currently have pretty basic setup but have tried all sorts of things which of course don’t work.

data() {
return {

computed: {
const params = new URLSearchParams();
params.append(‘year’, this.year);
return params;

getYears: function() {
params : this.axiosParams
}).then((response) => {
this.year =;

If I hardcode it like year: ‘2019’ in the data, everything works ok. when new to vue.js and Axios so any help would be greatly appreciated.

Solution :

You could just use a little javascript magic to get this year or an array of the years you want like so:

year() {
var now = new Date()
var nowy = now.getFullYear()

return nowy

This will return 2019

years() {
var yearsArray = []
var now = new Date()
for (let i = -1; i < 2; i++) {
var nowy = now.getFullYear() + i
return yearsArray

This will return an array like this: [2018, 2019, 2020]

Then it’s up to how you use that, you can send either this year or an array to the api.