mesemus / vuelidate-property-decorators

A thin wrapper of vuelidate library to simplify its usage with vue-class-component or vue-property-decorator.
https://github.com/mesemus/vuelidate-property-decorators
MIT License
27 stars 5 forks source link

Got Unexpected token 'export' when use package for NuxtJS #47

Open VDVT opened 2 years ago

VDVT commented 2 years ago

I got an issue when loading components in nuxtjs with mode SSR. Please see attachment

image
Rusinas commented 1 year ago

Same here

juventus18 commented 1 year ago

I was getting this too, in Nuxt if you are using an ES6 library, it needs to be transpiled first. Add this to your nuxt.config

build: {
    transpile: ['vuelidate-property-decorators']
},

Additional tip: If you don't want to make a Nuxt plugin for global use, be sure to extend the component with the mixins helper i.e.

import { Vue, Component, mixins } from 'nuxt-property-decorator';
import { validationMixin } from 'vuelidate';
import { Validations } from 'vuelidate-property-decorators';

import { required, minLength, between } from 'vuelidate/lib/validators';

@Component
export default class Login extends mixins(validationMixin) {
    name = '';
    age = 0;
    //
    @Validations()
    validations = {
        name: {
            required,
            minLength: minLength(4),
        },
        age: {
            between: between(20, 30),
        },
    };
}