繁体   English   中英

VueJs如何发送带有参数的发布请求?

[英]VueJs how to send a post request with parameters?

我以这种方式发送请求

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

如果您通过浏览器浏览,参数如下所示

在此处输入图片说明

在图像中,我显示的对象看起来像({“ something”:“ string”} :)

请注意,我的对象是另一个对象的键(如果使用json.stringfy(),我的对象仍将是另一个对象的键)为什么会发生以及如何制作普通对象?

我认为最好的方法是首先创建对象。

 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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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