Vue使用axios post方法发送json数据报415Unsupported Media Type

时间:2024-03-07 08:14:15

1.Vue使用axios post方法发送json数据

<template>
  <el-aside>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="审核选择">
        <el-switch
            v-model="form.status"
            active-text="审核通过"
            active-value="2"
            inactive-text="审核不通过"
            inactive-value="3"
            active-color="#13ce66"
            inactive-color="#ff4949">
        </el-switch>
      </el-form-item>

      <el-form-item label="处理原因">
        <el-input type="textarea" v-model="form.reason"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button @click="cancel">取消</el-button>
      </el-form-item>
    </el-form>

  </el-aside>
</template>

<script>
import axios from "axios";

export default {
  name: "StoreHandler",
  data() {
    return {
      form: {
        status: \'2\',
        reason: \'\'
      }
    }
  },

  methods: {
    onSubmit() {
      console.log(this)
      console.log(this.form.status)
      console.log(this.form.reason)
      console.log(this.$route.query.storeId)

      const jsons = {
        storeId:this.$route.query.storeId,
        status: this.form.status,
        reason: this.form.reason
      };

      let _this = this

      axios({
        method: \'post\',
        url: \'http://localhost:1111/waimai/store/updateStoreStatusAndReason\',
        data: JSON.stringify(jsons),
        headers: {
          \'Content-Type\': \'application/json;charset=UTF-8\'
        }
      }).then(function (res) {
        console.log(res)
        _this.$notify({
          title: \'提交成功\',
          message: \'处理结果\',
          type: \'success\'
        })

        _this.$router.push({
          path:\'/storeApplyList\'
        })
      })
    },

    cancel() {
      this.$router.push({
        path: \'/storeAppLyList\'
      })
    }
  },
}
</script>

<style scoped>

</style>