FormData 作为 vuex 动作的有效载荷

FormData as payload to vuex action

我需要帮助。无论如何要发送 FormData 作为 Vuex Action 的有效负载?

  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] error: no multipart boundary param in Content-Type

添加一个空 {} 作为您的操作的第一个参数,它应该可以工作。

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

Action handlers receive a context object which exposes the same set of methods/properties on the store instance, so you can call context.commit to commit a mutation, or access the state and getters via context.state and context.getters.

Reference