duanpuchun5275 2018-09-27 19:41
浏览 66
已采纳

如何使用PHP从VueJS发布数据?

Please Help me, How to post data using the request which made by Vue.js

There's Vue's code

let tests = {
    cat1: {
        name: 'Auth',
        items: {
            authorize2: {
                name: 'Successful',
                subname: '',
                request: {
                    method: 'POST',
                    link: 'auth',
                    data: {
                        login: 'admin',
                        password: 'password'
                    }
                },
                test: (result, status) => {
                    if (status.status == 200) {
                        return true;
                    }

                    return false;
                }
            }}}}

PHP page which receives this code doesn't have anything in POST data storage.

  • 写回答

1条回答 默认 最新

  • doudun2212 2018-09-28 10:05
    关注

    Originally Vue used the vue-resource package to perform POST requests via the $http instance property:

    login(){
        var data = {
          login: 'admin',
          password: 'password'
        }
        this.$http.post('/auth', data)
            .then(response => { /* success callback */ }, response => { /* error callback */ })
    }
    

    In Vue2 vue-resource was retired and they started to recommend Axios. They also offered a way to override the $http instance property allowing you to invoke the axios library in a similar way.

    this.$http.post('/auth', data)
        .then(response => { /* success callback */ })
        .catch(error => { /* error callback */ })
    

    Or you can just load the Axios Package and call it directly:

    const axios = require('axios');
    
    ...
    
    axios.post('/auth', data)
        .then(response => { /* success callback */ })
        .catch(error => { /* error callback */ })
    

    You could even choose to use vanilla js or another library like jQuery and use $.ajax() to make the request within your Vue instance, but using axios is the current recommendation from Vue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料