引入axios

This commit is contained in:
xing 2020-06-16 15:08:01 +08:00
parent 2d4abadfa8
commit 4a323995f9
2 changed files with 16 additions and 1 deletions

View File

@ -12,7 +12,7 @@
<el-input v-model="loginForm.password" type="password" prefix-icon="iconfont icon-3702mima"></el-input> <el-input v-model="loginForm.password" type="password" prefix-icon="iconfont icon-3702mima"></el-input>
</el-form-item> </el-form-item>
<el-form-item class="btns"> <el-form-item class="btns">
<el-button type="primary">登录</el-button> <el-button @click="submit" type="primary">登录</el-button>
<el-button @click="reset" type="info">重置</el-button> <el-button @click="reset" type="info">重置</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -42,6 +42,17 @@ export default {
} }
}, },
methods: { methods: {
submit () {
this.$refs.loginFormRef.validate(async valid => {
if (!valid) {
return
}
const { data: res } = await this.$http.post('login', this.loginForm)
if (res.meta.status !== 200) {
return console.log('login fail')
}
})
},
reset () { reset () {
this.$refs.loginFormRef.resetFields() this.$refs.loginFormRef.resetFields()
} }

View File

@ -5,8 +5,12 @@ import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css' import 'element-ui/lib/theme-chalk/index.css'
import './assets/fonts/iconfont.css' import './assets/fonts/iconfont.css'
import './assets/css/globel.css' import './assets/css/globel.css'
import axios from 'axios'
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
Vue.prototype.$http = axios
Vue.use(ElementUI) Vue.use(ElementUI)
Vue.config.productionTip = false Vue.config.productionTip = false
new Vue({ new Vue({