首页IT科技vue调取接口(vue调用后端接口)

vue调取接口(vue调用后端接口)

时间2025-04-28 22:46:45分类IT科技浏览4008
导读:1、在config文件下的index.js文件的proxyTable:{ }中写入...

1           、在config文件下的index.js文件的proxyTable:{ }中写入

/api: { target: http://localhost:8088/,//此处可以换成自己需要的地址 changeOrigin: true, pathRewrite: { ^/api: / } }

2                  、在main.js中写入 Vue.prototype.HOST = “/api            ”

3      、需要调用接口的方法:如login()方法

this.$axios({

url: this.HOST + ‘调用的接口’,

method: ‘方法:如post           、get’,

headers: {

//请求头           ,可以将token放在这里

‘key’:value

},

params: {

//需要传过去的参数

‘key’:value

}

}).then(res => {

//res为后端传回来的数据

})

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
揭秘seo搜索排名优化的真正含义是(揭秘SEO搜索排名优化的真正含义) 百度被广告占领(网站百度统计被恶意刷广告的处理方法)