ProxyTable doen't work in vuejs when call api



In config/index.js i config like like this

proxyTable: {
'/api': {
target: 'http://localhost:44322',
changeOrigin: true
}
},

我称之为get方法的这段代码。

<template>
<div>
<ul v-if="posts && posts.length">
<li v-for="post of posts" v-bind:key="post.employeeId">
<p><strong>{{post.firstName}}</strong></p>
<p>{{post.lastName}}</p>
<p>{{post.phoneNumber}}</p>
<p>{{post.dateOfBirth}}</p>
<p>{{post.email}}</p>
</li>
</ul>
<ul v-if="errors && errors.length">
<li v-for="error of errors" v-bind:key="error.id">
{{error.message}}
</li>
</ul>
</div>
</template>
<script>
import Axios from 'axios'
export default {
name: 'Axios',
data () {
return {
posts: [],
errors: []
}
},
// Fetches posts when the component is created.
created () {
Axios.get('/api/employee')
.then(response => {
// JSON responses are automatically parsed.
this.posts = response.data
})
.catch(e => {
this.errors.push(e)
console.log(e)
})
}
}
</script>

我想要当我打电话时

http://localhost:8080/#/axios

客户端对后端的调用:

http://localhost:44322/api/employee

但是什么也没发生,我在请求的标题中看到网址是:

localhost:8080

我确实在开发过程中流动了 Vuejs 的链接:https://vuejs-templates.github.io/webpack/proxy.html,部分 API 代理。对此有什么想法吗? 谢谢!!

您会在浏览器中看到请求 URLhttp://localhost:8080/api/employee

最后,请求将被传输到您在浏览器的网络面板中看不到的http://localhost: 44322/api/employee

最新更新