简体   繁体   中英

VueJs how to send a post request with parameters?

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 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM