I'm using vue cli3 for setup. I already have devServer api set up as such in vue.config.js
file:
devServer: {
proxy: {
'/api': {
target: 'http://localhost:1888/apps/test/mainapp.php/',
changeOrigin: true,
},
},
}
I also need to set path 'https://server/myapp/main.php/' as the production API path, but I can't seem to find any info in the documentation on how to do it. Any help is appreciated.
Brief example of what i'm doing in code:
methods: {
login() {
this.axios.post('/api/test')
.then((resp) => {
console.log(resp);
})
.catch(() => {
console.log('err:' , err);
});
},
},
You are using axios
in your code, so you can try:
// service.js
import axios from 'axios';
axios.defaults.baseURL = 'https://server/myapp/main.php/';
export default axios;
// main.js
Vue.prototype.$axios = axios;
// In your component
login() {
this.$axios.post('/api/test', data)
.then((resp) => {
console.log(resp);
})
.catch(() => {
console.log('err:' , err);
});
}
Then every request would send with the default baseUrl
you set.
Check out more options for axios
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With