Yarn Start or Yarn Serve while Doing Python API Development?
I know most people don't know how to use Reactjs or Vuejs while doing Python API development.
That's why I write this post, I want to give you a general idea of how to do Python Development while still have the hot load ability of front-end stuff.
Python Side
You just have to set debug=True and set CROS for all origins.
Javascript Side
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const axios = require('axios')
const TEST_URL = "/api/v1/test"
const GET_URL = "/api/v1/get"
export default new Vuex.Store({
state: {
host: "",
},
mutations: {
set_host(state, host) {
state.host = host
console.log(`We use ${host} as our API server.`);
},
},
actions: {
async determine_the_right_host(store) {
axios.post(TEST_URL, {
})
.then(function (response: any) {
store.commit("set_host", location.protocol + '//' + document.domain + ':' + location.port)
})
.catch(function (error: any) {
store.commit("set_host", location.protocol + '//' + document.domain + ':' + "12125")
//console.log(error);
});
},
async get_data(store) {
axios.post(store.state.host + GET_URL, {
})
.then(function (response: any) {
console.log(response.data);
})
.catch(function (error: any) {
console.log(error);
});
}
},
modules: {
}
})