从另一个函数内部触发方法

发布于 2025-01-22 00:43:51 字数 1879 浏览 0 评论 0原文

我有一种将数据发送到数据库的方法,可以使用@Click从按钮触发数据库,​​但是我想通过在条件函数中调用它来触发它,任何人都可以帮助吗? the post is edited so I want to add the addPatient method called right after submitted notification is triggered in else{}

  onSubmit () {


    namefRef.value.validate()
    namelRef.value.validate()
    birthdateRef.value.validate()

    if (namefRef.value.hasError || namelRef.value.hasError || birthdateRef.value.hasError ) {
      // form has error
    }
    else if (gender.value !== 'male'&& gender.value !== 'female') {
      $q.notify({
        color: 'negative',
        message: 'You need to choose a gender'
      })

    }
    else {

      $q.notify({

        icon: 'done',
        color: 'positive',
        message: 'Submitted',

      }),

      loadinga.value = true



      setTimeout(() => {loadinga.value = false }, 300)
    }

  },


}

},

data() {
    return{
       patient:{
          id:uid(),
          caption:'',
          namef:'',
          namel:'',
          age:'',
          lastappointment:'',
          location:'',
          photo:null,
          date:Date.now()
       },
   loading:false,

}

},

methods:{
   addPatient() {

  let formData = new FormData()
  formData.append('id', this.patient.id)
  formData.append('index', this.patient.index)
  formData.append('namef', this.namef)
  formData.append('namel', this.namel)
  formData.append('age', this.patient.age)
  formData.append('date', this.patient.date)
  formData.append('lastappointment', this.patient.lastappointment)
 //* formData.append('file', this.patient.photo, this.patient.id + '.png')
  this.$axios.post(`${ process.env.API}/createPatient`, formData).then(
    response => {
      console.log('response:',response)

    }).catch(err => {
    console.log('err:',err)
  })
}

I have a method that sends data to the database and can be triggered from a button using @click but I want to trigger it from another function by calling it in conditional function any one can help? the post is edited so I want to add the addPatient method called right after submitted notification is triggered in else{}

  onSubmit () {


    namefRef.value.validate()
    namelRef.value.validate()
    birthdateRef.value.validate()

    if (namefRef.value.hasError || namelRef.value.hasError || birthdateRef.value.hasError ) {
      // form has error
    }
    else if (gender.value !== 'male'&& gender.value !== 'female') {
      $q.notify({
        color: 'negative',
        message: 'You need to choose a gender'
      })

    }
    else {

      $q.notify({

        icon: 'done',
        color: 'positive',
        message: 'Submitted',

      }),

      loadinga.value = true



      setTimeout(() => {loadinga.value = false }, 300)
    }

  },


}

},

data() {
    return{
       patient:{
          id:uid(),
          caption:'',
          namef:'',
          namel:'',
          age:'',
          lastappointment:'',
          location:'',
          photo:null,
          date:Date.now()
       },
   loading:false,

}

},

methods:{
   addPatient() {

  let formData = new FormData()
  formData.append('id', this.patient.id)
  formData.append('index', this.patient.index)
  formData.append('namef', this.namef)
  formData.append('namel', this.namel)
  formData.append('age', this.patient.age)
  formData.append('date', this.patient.date)
  formData.append('lastappointment', this.patient.lastappointment)
 //* formData.append('file', this.patient.photo, this.patient.id + '.png')
  this.$axios.post(`${ process.env.API}/createPatient`, formData).then(
    response => {
      console.log('response:',response)

    }).catch(err => {
    console.log('err:',err)
  })
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文