vue这样做提交可以吗

                this.$http({url: 'http://localhost/wang/index.php/Home/Goods/createGoods', method: 'POST'}
                        ,{"cid": this.cid,"name":this.goodsname,"sort":this.sort,"price":this.price,"desc":this.desc}).then(function (response) {

                            alert("创建成功");

                }, function (response) {
                    // error callback
                });

值写得对不对
"name":this.goodsname
是不是name=goodsname

阅读 1.6k
1 个回答

如果你问的是对象里是否可以写name= goodsname,那不可以。

你的问题在于vue-resource的用法姿势不对,参数应该这么传:

this.$http({
    url: 'http://localhost/wang/index.php/Home/Goods/createGoods',
    method: 'POST',
    data: {
        cid: this.cid,
        name: this.goodsname,
        sort: this.sort,
        price: this.price,
        desc: this.desc
    }
}).then(function(response) {

    alert('创建成功');

}, function(response) {
    // error callback
});
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题