Vue中如何发起请求接口数据方法例子
在main.js添加如下代码
import axios from 'axios' // 配置请求的更路径 axios.defaults.baseURL = "http://www.laravel8.com/api/" Vue.prototype.$http = axios
使用方法
<script>
export default {
data(){
return{
// 登录表单数据绑定对象
loginForm:{
username:'',
password:''
},
}
},
methods:{
login(){
this.$refs.loginFormRef.validate(async valid=>{
if(!valid){
return;
}
const {data:res} = await this.$http.post('login',this.loginForm)
if(res.code !== 0)return console.log(res.msg)
console.log(res.msg)
})
}
}
}
</script>
关于简忆
简忆诞生的故事



粤ICP备16092285号
文章评论(0)