栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Vue

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Vue

1. Axios 基本使用 1.1 引言

Axios 是一个异步请求技术,核心作用就是用来在页面中发送异步请求,并获取对应数据在页面中渲染 页面局部更新技术 Ajax

1.2 Axios 的下载

中文网站:https://www.kancloud.cn/yunye/axios/234845

安装: https://unpkg.com/axios/dist/axios.min.js

1.3 GET方式的请求
	  //发送GET方式请求
    axios.get("http://localhost:8989/user/findAll?name=xiaochen").then(function(response){
        console.log(response.data);
    }).catch(function(err){
        console.log(err);
    });
1.4 POST方式请求
		//发送POST方式请求
    axios.post("http://localhost:8989/user/save",{
        username:"xiaochen",
        age:23,
        email:"xiaochen@zparkhr.com",
        phone:13260426185
    }).then(function(response){
        console.log(response.data);
    }).catch(function(err){
        console.log(err);
    });
1.5 axios并发请求

并发请求: 将多个请求在同一时刻发送到后端服务接口,最后在集中处理每个请求的响应结果

function getUserAccount() {
  return axios.get('/user/12345');
}

function getUserPermissions() {
  return axios.get('/user/12345/permissions');
}

axios.all([getUserAccount(), getUserPermissions()])
  .then(axios.spread(function (acct, perms) {
    // 两个请求现在都执行完成
}));
1.6 put方式的请求
   axios.put("http://localhost:8080/test",{name:"松崎乡",age:"21"}).then(function (response) {
        console.log(response);
    }).catch(function (error) {
        console.log(error);
    });
1.7 path方式的请求
 axios.path("http://localhost:8080/test",{name:"松崎乡",age:"21"}).then(function (response) {
        console.log(response);
    }).catch(function (error) {
        console.log(error);
    });
1.8 delete方式的请求(同理)
 axios.delete("url?id=21").then(function (response) {

    }).catch(function (error) {

    });
1.9 拦截器

拦截器:请求拦截器 + 响应拦截器

配置一个拦截器


案例:员工信息管理

我们通过基础指令和Axios+Bootstrap,结合我们的SpringBoot快速打通并实现一个简单的CRUD

实现效果

前端代码:




    
    员工列表管理页面
    
    


        

{{msg}}

编号 姓名 年龄 工资 操作
{{emp.id}} {{emp.name}} {{emp.age}} {{emp.salary}} 删除    修改

参考视频:编程不良人Vue全家桶

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/530696.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号