我个人使用 Nuxt.js 开发应用程序。
我使用axios进行API通信,我使用代理来避免CROS限制,但是我不明白向多个服务器发送请求时如何设置代理。
我在网上搜了一下,没有找到可以解决的文章,所以在这里问了一个问题。
我尝试自己编写代码,但如果您能给我一些建议(例如如何这样做),那将非常有帮助。
你想要达到的目标
数据库使用 DynamoDB。 我想在DynamoDB中注册发布的内容并从数据库中获取。
signUp(){
this.$axios.$get('/signUp',
{
m_users: {
user_name: this.username,
mailaddress: this.mailaddress,
password: this.password
}
})
.then(res => {
console.log(res);
});
},
async getList() {
await this.$axios.$get('/api')
.then(res => {
console.log(res);
});
}
async addPost() {
await this.$axios.post('/post',
{
t_items: {
item_id: this.nextId,
shop_name: this.shop,
item_name: this.name,
item_price: this.price,
item_unit: this.unit,
post_date: date
}
}
)
.then(res => {
console.log(res);
})
proxy: {
'/api': {
target: 'URL',
pathRewrite: {
'^/api': ''
}
},
'/signUp': {
target: 'URL',
pathRewrite: {
'^/api': ''
}
},
'/post': {
target: 'URL',
pathRewrite: {
'^/api': ''
}
}
},
axios: {
prefix: '/api',
},
这是正确的吗?