请求后台配置 axios 使用
//请求后台配置 import axios from 'axios' axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/' Vue.prototype.$http = axios
发送请求(接口名:login,请求类型:post,请求参数:this.loginForm (对象))
this.$http.post('login', this.loginForm)
使用async和await处理promise
this.$refs.formRef.validate(async valid => { // console.log(valid) if (!valid) return const { data: res } = await this.$http.post('login', this.loginForm) console.log(res) if (res.meta.status === 200) { console.log('登录成功') } else { alert(res.meta.msg) } })
注意需要在.eslintrc.js中配置
parserOptions: {
ecmaVersion: 8,
sourceType: 'module',
allowImportExportEverywhere: true //ignore eslint error: 'import' and 'export' may only appear at the top level
},