Request failed with status code 404
On site restoration
This is in the Vue project. Mock is used to simulate data, and false data is tested. After the background interface is developed, it is connected with real data main.js It’s written like this [except for the places with long horizontal line (- —), other places are ignored for the time being]
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import VueRouter from 'vue-router'
import store from './vuex/store'
import Vuex from 'vuex'
import routes from './routes'
import Mock from './mock'//----------------------------Pay attention to this place--mock
import axios from 'axios'//----------------------------Pay attention to this place--axios
import ajax from './lib/ajax/Ajax.js'//----------------Pay attention to this place--axios
Mock.bootstrap();//------------------------------------Pay attention to this place--mock
import 'font-awesome/css/font-awesome.min.css'
Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(Vuex)
Vue.prototype.$ajax = axios;//---------------------------Pay attention to this place--axios
Vue.prototype.$http = ajax;//----------------------------Pay attention to this place--axios
const router = new VueRouter({
routes
})
router.beforeEach((to, from, next) => {
if (to.path == '/login') {
sessionStorage.removeItem('user');
}
let user = JSON.parse(sessionStorage.getItem('user'));
if (!user && to.path != '/login') {
next({path: '/login'})
} else {
next()
}
})
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
Method post call
getCompanyInfo: function () {
this.$ajax.get('cszj/company/getCompanyById').then((response) => {
alert(response.data);
}).catch((response) => {
alert("Error:" + response);
})
}
Errors in execution
Cause of error
Mock conflicts with Axios
Solution
Comment out mock
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import VueRouter from 'vue-router'
import store from './vuex/store'
import Vuex from 'vuex'
import routes from './routes'
//import Mock from './mock'//----------------------------Pay attention to this place--mock
import axios from 'axios'//----------------------------Pay attention to this place--axios
import ajax from './lib/ajax/Ajax.js'//----------------Pay attention to this place--axios
//Mock.bootstrap();//------------------------------------Pay attention to this place--mock
import 'font-awesome/css/font-awesome.min.css'
Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(Vuex)
Vue.prototype.$ajax = axios;//---------------------------Pay attention to this place--axios
Vue.prototype.$http = ajax;//----------------------------Pay attention to this place--axios
const router = new VueRouter({
routes
})
router.beforeEach((to, from, next) => {
if (to.path == '/login') {
sessionStorage.removeItem('user');
}
let user = JSON.parse(sessionStorage.getItem('user'));
if (!user && to.path != '/login') {
next({path: '/login'})
} else {
next()
}
})
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
After testing the post method, you can request it!
Similar Posts:
- [Solved] Uniapp Axios appears in wechat applet index.js? [SM]: 33 errortyerror: l is not a function error
- Axios encapsulate error: cyclic dependency [How to Solve]
- Axios gets the upload progress error: xhr.upload.addEventListener is not a function
- How to Solve Vue3 ts setup getCurrentInstance Error
- [Solved] (6) Axios error reporting, cannot read property ‘protocol’ of undefined
- [Solved] Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location
- [Solved] axios Configurate baseURL Error: Uncaught TypeError: Cannot set properties of undefined (setting ‘baseURL’)
- Using Vue + Axios: axios.post error: request failed with status code 400 is one of the solutions
- Request failed with status code 500 & Self referencing loop detected for property ‘xx‘ with type