vue的接口继承给原型

2020-06-10  本文已影响0人  最念倾城

在main。js文件中

//axios配置
import axios from 'axios'
axios.defaults.baseURL = 'https://www.liulongbin.top:8888/api/private/v1/'
Vue.prototype.$http = axios

在你想发起接口请求的地方

    login(){
       this.$refs.loginFormRef.validate(async ref=>{
        //  console.log(ref);
        if(!ref) return
         const {data:res} =await this.$http.post('login',this.loginForm)
        if(res.meta.status !==200)return this.$message.error('登陆失败');
        ('登录失败');
      
      
      })
    }
上一篇下一篇

猜你喜欢

热点阅读