在config / index.js中,我这样配置
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
但是什么也没发生,我在请求的标头中看到该URL是:
localhost:8080
我确实在开发过程中流动了vuejs的链接:https://vuejs-templates.github.io/webpack/proxy.html,部分API代理。有什么想法吗?谢谢!!
在config / index.js中,我像这样配置proxyTable:{'/ api':{目标:'http:// localhost:44322',changeOrigin:true}},这段代码我叫get方法。
您将在浏览器中看到请求网址为http://localhost:8080/api/employee