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

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

时间2025-06-21 02:23:52分类IT科技浏览4508
导读: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
vue-router failed to resolve(关于Vue3警告:Failed to resolve component:XXX的解决办法)