【问题标题】:How can post multible variable with axios?如何用 axios 发布多个变量?
【发布时间】:2017-12-19 08:56:41
【问题描述】:

我尝试了一篇带有多个变量的 axios 帖子。但我不能。 Register.vue 发布用户名、名字和姓氏。一项成功发送,因为树项无法发送。我将数据从“register.vue”发送到“routes.php”。我正在搜索这个但找不到。人们只说“register.vue”,没有人不说routes.php。

 register.vue:
             axios.post(`http://localhost:8000/register`,
                params:{
                  un=this.un,
                  fn=this.fn,
                  ln=this.ln
                })
                .then(function(response){
                  console.log("data------");
                  console.log(response.data);
                  console.log("data-------");
                });                                                                                                     


routes.php:  

Route::post('register',function(Request $un,Request $fn,Request $ln)
  {
    $redis=Redis::connection();
    $un=$un->input();
    $fn=$fn->input();
    $ln=$ln->input();
    reset($un,$fn,$ln);
    $tobe=$redis->exists("$un:$fn:$ln");
    return $tobe;
  });

【问题讨论】:

标签: php laravel vue.js axios


【解决方案1】:

1) 移除 params 对象,它应该只是对象 2)你以错误的方式声明变量,应该是这样 - un:this.un

axios.post(`http://localhost:8000/register`, {
                    un: this.un,
                    fn: this.fn,
                    ln: this.ln
                }).then(function (response) {
                    console.log(response.data);
                });

【讨论】:

    猜你喜欢
    • 2020-08-06
    • 2020-04-23
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-31
    • 2018-10-13
    • 1970-01-01
    相关资源
    最近更新 更多