File tree Expand file tree Collapse file tree 5 files changed +131
-0
lines changed Expand file tree Collapse file tree 5 files changed +131
-0
lines changed Original file line number Diff line number Diff line change 1+ <template >
2+ <div v-if =" $errors.has(input)" class =" txt-darkRed" >
3+ {{ $errors.first(input) }}
4+ </div >
5+ </template >
6+ <script >
7+
8+ export default {
9+
10+ props: [' input' ],
11+
12+ data (){
13+ return {}
14+ },
15+
16+ methods: {},
17+
18+ computed: {},
19+
20+ watch: {},
21+
22+ mounted (){
23+
24+ }
25+ }
26+
27+ </script >
Original file line number Diff line number Diff line change 1+ class Errors {
2+
3+ constructor ( ) {
4+ this . errors = { } ;
5+ }
6+
7+ has ( key ) {
8+ return this . errors [ key ] !== undefined
9+ }
10+
11+ first ( key ) {
12+ if ( this . has ( key ) ) {
13+ return this . errors [ key ] [ 0 ]
14+ }
15+ }
16+
17+ get ( key ) {
18+ if ( this . has ( key ) ) {
19+ return this . errors [ key ]
20+ }
21+ }
22+
23+ all ( ) {
24+ return this . errors
25+ }
26+
27+ fill ( values ) {
28+ this . errors = values
29+ }
30+
31+ flush ( ) {
32+ this . errors = { } ;
33+ }
34+
35+ }
36+
37+ export default new Errors ( )
Original file line number Diff line number Diff line change 1+
Original file line number Diff line number Diff line change 1+ import Errors from './Errors'
2+ import ErrorComponent from './ErrorComponent.vue'
3+
4+
5+ class Validator {
6+
7+ install ( Vue ) {
8+
9+ Vue . component ( 'error' , ErrorComponent ) ;
10+
11+ if ( Vue . http ) {
12+ Vue . http . interceptors . push ( ( request , next ) => {
13+ next ( response => {
14+ if ( response . status === 422 ) {
15+ Errors . fill ( response . body )
16+ }
17+ } ) ;
18+ } ) ;
19+ }
20+
21+ Vue . mixin ( {
22+
23+ beforeCreate ( ) {
24+ //errors
25+ this . $options . $errors = { } ;
26+ Vue . util . defineReactive ( this . $options , '$errors' , Errors ) ;
27+ if ( ! this . $options . computed ) {
28+ this . $options . computed = { }
29+ }
30+ this . $options . computed [ "$errors" ] = function ( ) {
31+ return this . $options . $errors ;
32+ } ;
33+ } ,
34+
35+ } )
36+
37+ }
38+
39+ }
40+
41+ export default new Validator ( )
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " laravel-vue-validator" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " Simple package to display error in vue from laravel validation" ,
5+ "main" : " index.js" ,
6+ "scripts" : {
7+ "test" : " echo \" Error: no test specified\" && exit 1"
8+ },
9+ "repository" : {
10+ "type" : " git" ,
11+ "url" : " git+https://github.com/val-bubbleflat/laravel-vue-validator.git"
12+ },
13+ "keywords" : [
14+ " laravel" ,
15+ " vue" ,
16+ " validate" ,
17+ " validator"
18+ ],
19+ "author" : " val bubbleflat <valentin@bubbleflat.com> (bubbleflat.com)" ,
20+ "license" : " MIT" ,
21+ "bugs" : {
22+ "url" : " https://github.com/val-bubbleflat/laravel-vue-validator/issues"
23+ },
24+ "homepage" : " https://github.com/val-bubbleflat/laravel-vue-validator#readme"
25+ }
You can’t perform that action at this time.
0 commit comments