axios的使用.md

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/marko_zheng/article/details/82764982

axios的使用

在本次的项目中使用Vue构建 的项目需要向后台发起请求,Vue本身并不支持发起请求,需要使用vue-sour或者axios等插件,在新版本中对vue-souurce的支持并不友好,我在这里使用了axios,引入的方式有多重,这里只记录通过标签对侵入的方式

引入
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

配置跨域

 proxyTable: {
        '/ajax': {
        target: 'http://cgqsrs.server.com/Duse.aspx',
            changeOrigin: true,
            pathRewrite: {
                '^/ajax': ''
            }
        }
    },

在组件中使用

axios.post('/ajax/Login', {
                    uname:'test',
                    pass:"1",
                    vcode:"asdf"
                })
                    .then(function (response) {
                        console.log(response);
                    })
                    .catch(function (error) {
                        console.log(error);
                    });

猜你喜欢

转载自blog.csdn.net/marko_zheng/article/details/82764982