0

这是我的 Html 模板
我是惯性 js 的新手,我正在尝试使用“提交”方法提交数据我不知道为什么它没有定义

<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)
            
        
        }
    }
}

这是我的脚本:

` 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)
            
        
        }
    }
}

`

4

1 回答 1

2

在组件的脚本部分更改methodmethods

<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>
于 2020-11-28T09:51:57.997 回答