-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
53 lines (40 loc) · 1.28 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import Errors from './Errors'
import ErrorComponent from './ErrorComponent.vue'
class Validator{
install(Vue){
Vue.component('error', ErrorComponent);
if(Vue.http){
Vue.http.interceptors.push((request, next) => {
next(response => {
if(response.status === 422){
Errors.fill(response.body)
}
});
});
}
if (axios) {
axios.interceptors.response.use((response) => {
return response;
}, (error) => {
if (error.response.status === 422) {
Errors.fill(error.response.data.errors)
}
return Promise.reject(error);
});
}
Vue.mixin({
beforeCreate(){
//errors
this.$options.$errors = {};
Vue.util.defineReactive(this.$options, '$errors', Errors);
if(!this.$options.computed){
this.$options.computed = {}
}
this.$options.computed["$errors"] = function() {
return this.$options.$errors;
};
},
})
}
}
export default new Validator()