javascript - VueJs how to send a post request with parameters? - Stack Overflow

I'm sending the request this waythis.$http.post('http:localhost:3000store', {somethin

I'm sending the request this way

this.$http.post('http://localhost:3000/store', {something: 'string'}, {
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
      }})

And if you look through the browser, the parameters look like this

enter image description here

in image i show object which look like ({"something":"string"}:)

Note that my object is the key of another object (If you use json.stringfy (), my object will still be the key of another object) Why did it happen and how to make a normal object?

I'm sending the request this way

this.$http.post('http://localhost:3000/store', {something: 'string'}, {
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
      }})

And if you look through the browser, the parameters look like this

enter image description here

in image i show object which look like ({"something":"string"}:)

Note that my object is the key of another object (If you use json.stringfy (), my object will still be the key of another object) Why did it happen and how to make a normal object?

Share Improve this question asked Jun 11, 2017 at 12:14 Nimble StalkerNimble Stalker 3735 silver badges15 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

I think the best way to do this is create the object first.

var something = "key";
var obj = {};
obj[something] = 'string';

this.$http.post('http://localhost:3000/store', obj, {
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
      }})

<script>

var mixin = {


        var url = 'http://localhost/vue/serv.php';
        this.$http.get(url, {params: {action: 'buscar', userid:'2'}, headers: {'X-Custom': '...'}}).then(response => {
            this.usuarios = response.body;
            console.log(response);
        }, response => {
            console.log(error);
        });
}    
    }


new Vue({
    el: '#resultado', 

    mixins: [mixin], 

    data:{
        titulo: "Vue lmideias",       
        usuarios: []        
    } 

});

</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745235712a4617880.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信