【发布时间】:2020-04-09 20:35:15
【问题描述】:
我正在运行一个后端服务,它在这个地址返回一些数据:http://localhost:8080/vuejs-demo/rest/customers
然后我有一个 index.html 页面,位于:http://localhost:8080/vuejs-demo/index.html,它从 REST 服务获取数据:
listUsers: function() {
axios.get("/vuejs-demo/rest/customers", {
})
.then(response => {
this.users = response.data
})
}
问题是,我不想硬编码根 Web 上下文信息“vuejs-demo”。 由于 index.html 页面和 REST 服务都在“vuejs-demo”Web 上下文中,我假设我可以直接调用“rest/customers”端点。 但是使用:
axios.get("rest/customers", {
})
.then(response => {
this.users = response.data
})
}
未能包含 Web 上下文,导致 http://localhost:8080//vuejs-demo/rest/customers 同样使用“/rest/customers”会导致http://localhost:8080/rest/customers,这也会导致404错误。 有没有办法解决这个问题? 谢谢
【问题讨论】:
标签: javascript vue.js axios