【问题标题】:How to send form data in vue to variable as json using axios?如何使用axios将vue中的表单数据作为json发送到变量?
【发布时间】:2019-12-09 10:39:57
【问题描述】:

现在我有方法:

      let newFormData = {
        productName: this.productName,
        productModel: this.productModel,
        prodDescription: this.prodDescription,
        prodPrice: this.prodPrice,
        promoPrice: this.promoPrice
      };
      console.log(newFormData);
      e.target.reset();
    },

我想将此表单数据发送到文件,并将其保存为 json 中的变量

【问题讨论】:

    标签: vue.js axios


    【解决方案1】:

    首先你应该有一个提交表单数据的路由,然后你可以像这样提交表单:

    axios.post('http://localhost:3030/api/new/post', 
        this.productName,
        this.productModel,
        this.prodDescription,
        this.prodPrice,
        { headers: {
          'Content-type': 'application/x-www-form-urlencoded',
          }
        }).then(response => ....);
    

    【讨论】:

      猜你喜欢
      • 2021-10-20
      • 2021-03-09
      • 2018-12-24
      • 1970-01-01
      • 2017-03-29
      • 2017-03-12
      • 1970-01-01
      • 2021-07-03
      • 2019-06-15
      相关资源
      最近更新 更多