programing

vuex 작업에 대한 페이로드로 FormData

bestcode 2022. 7. 10. 21:19
반응형

vuex 작업에 대한 페이로드로 FormData

도움이 필요해요Vuex Action의 페이로드로 FormData를 전송할 수 있습니까?

  methods: {
    ...mapActions({
      sendMessage: 'modules/modal/send_message'
    }),
    Send() {
      this.End = !this.End
      this.AutoClose()
      this.msg.append('name', this.Name)
      this.msg.append('phone', this.Phone)
      console.log(this.msg)
      this.sendMessage(this.msg)
    },

액션에 있어서

const actions = {
  send_message(payload) {
    Axios({
      method: 'post',
      url: 'http://localhost:8080/api/content/create?type=Emails',
      data: payload,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  }
}

그러나 서버 응답:

[Create] 오류: Content-Type에 다중 부분 경계 매개 변수가 없습니다.

빈칸 추가{}당신의 행동에 대한 첫 번째 논거로, 그리고 효과가 있을 것입니다.

const actions = {
   send_message({}, payload) {
      ...

액션 핸들러는 스토어 인스턴스에서 동일한 메서드/속성 세트를 공개하는 컨텍스트개체를 수신하므로 context.commit을 호출하여 변환을 커밋하거나 context.state 및 context.getters를 통해 상태와 getter에 액세스할 수 있습니다.

언급

언급URL : https://stackoverflow.com/questions/60190738/formdata-as-payload-to-vuex-action

반응형