irankhostravi irankhostravi - 3 months ago 64
Ajax Question

Property or method "onFileChange" is not defined on the instance but referenced during render


<!doctype html>
<html lang="{{ config('app.locale') }}">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="csrf-token" content="{{ csrf_token() }}">
<link rel="stylesheet" href="/css/app.css">

<div id="app">

<script src="/js/app.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#form').on('submit', function(e){
let name = $('#name').val();
let pic = $('#pic')[0].files[0];
let _token = $('input[name="_token"]').val();
let formData = new FormData();
formData.append('name' ,name);
formData.append('pic' ,pic);

method: 'POST',
url: '/getData',
data : formData,
contentType : false,
processData : false,
headers : {
'X-CSRF-TOKEN' : _token
}).done(function (msg){


<div class="container">
<form @submit.prevent="onSubmit" class="form-horizontal">
<div class="form-group">
<label class="control-label" v-model="name">Name
<input type="text" class="form-control" name="name" placeholder="Name">
<div class="form-group">
<label class="control-label">Pic
<input type="file" class="form-control" @change="onFileChange($event)" placeholder="Picture">

<button class="btn btn-danger" type="submit">Send</button>


export default {
data() {
return {
name : '',
pic: null
method: {
this.pic =[0];
onSubmit() {
console.log(, this.pic);


When I send data to blade page it is not working.

[Vue warn]: Property or method "onFileChange" is not defined on the
instance but referenced during render. Make sure that this property is
reactive, either in the data option, or for class-based components, by
initializing the property. See:


Answer Source

It should be methods instead of method

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download