Javascript 如何避免在axios.get中使用Web上下文
Javascript 如何避免在axios.get中使用Web上下文,javascript,vue.js,axios,Javascript,Vue.js,Axios,我正在运行一个后端服务,该服务在以下地址返回一些数据: 然后,我有一个index.html页面,位于:从REST服务获取数据: listUsers: function() { axios.get("/vuejs-demo/rest/customers", { }) .then(response => { this.users = response.data }) } 问题是,我不想硬编码根Web上下文信息“
我正在运行一个后端服务,该服务在以下地址返回一些数据:
然后,我有一个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上下文,导致
使用“/rest/customers”也会导致404错误。
有没有办法绕过这个问题?
谢谢导入axios后,您可以,其中一个是基本url:
import axios from 'axios'
axios.defaults.baseURL = 'http://localhost:8080/vuejs-demo/rest';