-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathtest.js
34 lines (34 loc) · 988 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const Test = Vue.component("test-view", {
template: "#test-view-template",
data: function() {
return {
questions: [],
answers: {},
currentRoute: "1"
};
},
created: function() {
var self = this;
$.getJSON("data/questions.json", function(data) {
self.questions = data;
});
},
computed: {
currentQuestion: function() {
return parseInt(this.$route.params.question) - 1;
},
paginationStart: function() {
return Math.max(0, this.currentQuestion - 2);
},
paginationEnd: function() {
return Math.min(this.paginationStart + 5, this.questions.length - 1);
}
},
methods: {
answer: function(state) {
var vm = this;
vm.answers[vm.currentQuestion] = state;
vm.$router.push({name: "test", params: {question: vm.currentQuestion + 1}});
}
}
});