"Uncaught Syntaxerror: Unexpected token <" with vuejs

Asked

Viewed 425 times

0

I am getting this error on multiple files.

Uncaught Syntaxerror: Unexpected token <

The Debugger says it is . js file, but sends me to html files and shows the error right in the first line of html, where it has doctype. There is no syntax error because the code was only copied from an existing project.

Some features and methods within the . js files failed to work.

Can anyone help me with this error? All I find is nothing related to what I need.

Follow the files that Debugger claims the error:

script js.

$(document).ready(function(){

$('.inicial .btn-login').click(function(){
    $('body').addClass('inicial-login');
});

$('#voltarHome').click(function(){
    $('body').removeClass('inicial-login');
});

$('.nav-img').click(function(){
    $('.nav-links').toggle('300');
    $('.sidebar').removeClass('on');
});

$('.click-sidebar').click(function(){
    $('.sidebar').toggleClass('on');
    $('.nav-links').hide('300');
});

$('#post-categoria').change(function(){
    if( $(this).val() == 'venda'){
        $('#vendaetroca').toggle('100');
    }
});

});

Vue-api-Register-candidate.js

import Form from './core/Form';
//import Axios from 'axios';

/*Os seguintes imports estão comentandos e deixados no código para possível uso futuro*/
//import Modal from './components/Modal.vue';
//import Datepicker from "./vue2-datepicker.js";

var vm = new Vue({
    el: '#candidate-register',
    data: {
        form: new Form(),
        image: "./img/img-placeholder.png",
        name_image: "",
        name: "",
        name_file_video: "",
        name_file: "",
        resume_file: "",
        video_file: "",
        selectFunction: "",
        cpf: "",
        email: "",
        cellphone: "",
        state: "",
        neighborhood: "",
        city: "",
        adress: "",
        street_number: "",
        complement: "",
        hiring_type: "",
        intended_salary: "",
        description: "",
        complement: "",
        id: "",
        id_user: "",
        password: "",
        password_confirm: "",
        logged: false,
    },
    mounted() {
        if (localStorage.getItem('id') != null) {
            this.logged = true;
        }
    },
    created: function () {
        if (localStorage.getItem('id') != "" && localStorage.getItem('id_user')) {
        axios.defaults.headers.post['Authorization'] = 'Bearer ' + localStorage.getItem('token');
        axios.defaults.headers.post['Accept'] = 'application/json';
        axios.defaults.headers.post['Content-Type'] = 'application/json';

        //Traz o candidato logado. URL de edição de candidate
        axios.post("url_aqui", {
            id: localStorage.getItem('id')
        }).then(response => {
            console.log(response.data.data);
            this.image = response.data.data.profile_image;
            this.name = response.data.data.name;
            this.cpf = response.data.data.cpf;
            this.email = response.data.data.email;
            this.cellphone = response.data.data.cellphone;
            this.state = response.data.data.state;
            this.neighborhood = response.data.data.neighborhood;
            this.city = response.data.data.city;
            this.adress = response.data.data.adress;
            this.street_number = response.data.data.street_number;
            this.complement = response.data.data.complement;
            this.hiring_type = response.data.data.hiring_type;
            this.intended_salary = response.data.data.intended_salary;
            this.description = response.data.data.description;
            this.resume_file = response.data.data.resume_file;
            this.selectFunction = response.data.data.id_function_candidate;
            this.id = response.data.data.id;
            this.id_user = response.data.data.id_user;
            this.complement = response.data.data.complement;
            this.video_file = response.data.data.video_file;

        }).catch(error => {
            console.log(error);
        })
    }

},
methods: {
    processForm() {
        if (this.id == "" && this.id_user == "") {
            this.form.data.name = this.name;
            this.form.data.cpf = this.cpf;
            this.form.data.email = this.email;
            this.form.data.cellphone = this.cellphone;
            this.form.data.state = this.state;
            this.form.data.neighborhood = this.neighborhood;
            this.form.data.city = this.city;
            this.form.data.adress = this.adress;
            this.form.data.street_number = this.street_number;
            this.form.data.complement = this.complement;
            this.form.data.hiring_type = this.hiring_type;
            this.form.data.intended_salary = this.intended_salary;
            this.form.data.description = this.description;
            this.form.data.name_image = this.name_image;
            this.form.data.name_file_video = this.name_file_video;
            this.form.data.name_file = this.name_file;
            this.form.data.id_function_candidate = this.selectFunction;
            this.form.data.complement = this.complement;
            this.form.data.password = this.password;
            this.form.data.password_confirm = this.password_confirm;
            this.form.data.id = null;
            this.form.data.id_user = null;

            this.form.submit("url_aqui", this.onSuccess);

        } else {

            this.form.data.name = this.name;
            this.form.data.cpf = this.cpf;
            this.form.data.email = this.email;
            this.form.data.cellphone = this.cellphone;
            this.form.data.state = this.state;
            this.form.data.neighborhood = this.neighborhood;
            this.form.data.city = this.city;
            this.form.data.adress = this.adress;
            this.form.data.street_number = this.street_number;
            this.form.data.complement = this.complement;
            this.form.data.hiring_type = this.hiring_type;
            this.form.data.intended_salary = this.intended_salary;
            this.form.data.description = this.description;
            this.form.data.name_image = this.name_image;
            this.form.data.name_file_video = this.name_file_video;
            this.form.data.name_file = this.name_file;
            this.form.data.id_function_candidate = this.selectFunction;
            this.form.data.complement = this.complement;
            this.form.data.id = this.id;
            this.form.data.id_user = this.id_user;
            this.form.data.password = this.password;
            this.form.data.password_confirm = this.password_confirm;

            this.form.submit("url_aqui", this.onSuccess);
        }

    },
    onSuccess(response) {
        try {
            if (response.data.result == true) {
                if(localStorage.getItem('id') == null){
                    alert("Cadastro realizado com sucesso!\nVocê será redirecionado para fazer o login.");
                    window.location.href = "index.html";
                }else{
                    alert("Edições salvas!");
                }


                this.form.reset();

                this.$refs.modal.configModal('Sucesso', 'Registro salvo!', 'OK', '', function () {
                    util.goBack();
                });
                this.$refs.modal.show(2500);
            } else {
                alert(response.data.msg);
                this.$refs.modal.configModal('Aviso', response.data.msg, '', 'OK');
                this.$refs.modal.show();
            }
        } catch (e) {
            console.log(e);
        }
    },
    //Para Salvar Imagem
    onFileChange(e, type) {
        var files = e.target.files || e.dataTransfer.files;

        if (type == 1) {
            this.name_image = files[0].name;
        } else if (type == 0) {
            this.name_file_video = files[0].name;
        } else {
            this.name_file = files[0].name;
        }

        if (!files.length)
            return;
        this.createImage(files[0], type);
    },

    createImage(file, type) {
        var image = new Image();
        var reader = new FileReader();
        var vm = this;

        if (type == 1) {
            reader.onload = (e) => {
                vm.image = e.target.result;
                this.form.data.image_b64 = e.target.result;
            };

            reader.readAsDataURL(file);
        } else if (type == 0) {
            reader.onload = (e) => {
                this.form.data.video_b64 = e.target.result;
            };

            reader.readAsDataURL(file);
        } else {
            reader.onload = (e) => {
                this.form.data.file_b64 = e.target.result;
            };

            reader.readAsDataURL(file);
        }
    },

    backToHome() {
        if (this.id == localStorage.getItem('id')) {
            console.log("entrou no if");
            localStorage.clear();
            window.location.href = "index.html";
        } else {
            console.log("entrou no else");
            window.location.href = "index.html";
        }
    }
}
})

Thanks in advance.

  • Click [Edit] and post your code.

  • Gilherme, your question has very little detail of the problem and it gets hard to really help without polluting comments like this one mine :D - Edit the question and add the rest of the bug, to find out which file it was in or if it is a configuration problem of some webpack download.

  • @Fernandosavio has nothing else, just that. Uncaught Syntaxerror: Unexpected token <. I get 3 of this in all, one for the Vue.js:1 file, one for my script.js:1, and one for an api. I’ll edit and put the code of each one here to verify. But as I said, the project was only imported into the Vue structure, before it worked correctly so I think there is no syntax error :s. Give me a minute to post here

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.