0
votes

this is my Html template
I am new to inertia js here I am trying to submit the data with the method 'submit' I don't know why it's not defined

<script>
import AppLayout from '@/Layouts/AppLayout'
//import Welcome from '@/Jetstream/Welcome'

export default {
    components: {
        AppLayout,  
    },
    data(){

        return{
          reactive:true,
            form:{
                course_title: null,
                about:null
            }
        }
    },

    method: {
        submit(){

          const data =new FormData()
          data.append('course_title', this.form.course_title || '')
          data.append('about', this.form.about|| '')

          this.$inertia.post(this.route('createcourse'),data)
            
        
        }
    }
}

this is my script:

` import AppLayout from '@/Layouts/AppLayout' //import Welcome from '@/Jetstream/Welcome'

export default {
    components: {
        AppLayout,  
    },
    data(){

        return{
          reactive:true,
            form:{
                course_title: null,
                about:null
            }
        }
    },

    method: {
        submit(){

          const data =new FormData()
          data.append('course_title', this.form.course_title || '')
          data.append('about', this.form.about|| '')

          this.$inertia.post(this.route('createcourse'),data)
            
        
        }
    }
}

`

1
on vue instance we have "methods" object but you defined it as "method". try fixing this typo and see if it helps or nothamid niakan

1 Answers

2
votes

Change method to methods in the script section of the component

<script>
    import AppLayout from '@/Layouts/AppLayout'
    //import Welcome from '@/Jetstream/Welcome'

    export default {
        components: {
            AppLayout,  
        },
        data(){
    
            return{
              reactive:true,
                form:{
                    course_title: null,
                    about:null
                }
            }
        },

        methods: { //fix the typo here
            submit(){

              const data =new FormData()
              data.append('course_title', this.form.course_title || '')
              data.append('about', this.form.about|| '')

              this.$inertia.post(this.route('createcourse'),data)
                
            
            }
        }
    }
</script>