Axios 是一个基于 promise HTTP 库,可以用在浏览器和 node.js 中 。axios的github:https://github.com/axios/axios
 
(1)首先搭建好Maven+SSM的后台架构:
Vue.js ajax
 
 
(2)在user.js中书写
 
var vue = new Vue({
    el: "#app",
    data: {
        user: {id:"",name:"",money:""},
        userList: []
    },
    methods: {
        findAll: function () {
            var _this = this;//此处是将Vue的this对象用_this保存,防止和下面的axious的this对象冲突
            axios.get("/SSM/account/findAll.do").then(function (response) {
                _this.userList = response.data;
                console.log(_this.userList);
            }).catch(function (err) {
                console.log(err);
            });
        },
        findById: function (userid) {
            var _this = this;
            axios.get("/SSM/account/findById.do", {//参数用两组大括号
                params: {
                    id: userid
                }
            }).then(function (response) {
              _this.user = response.data;
                $('#myModal').modal("show");//启用模态窗口来进行显示
            }).catch(function (err) {
            });

        },
        update: function (user) {
            var _this = this;
            axios.post("/SSM/account/update.do",_this.user).then(function (response) {
                _this.findAll();
            }).catch(function (err) {
            });
        }
    },
    created:function(){//当页面加载的时候触发请求,查询所有
        this.findAll();
    }
});

(3)user.html页面上的部分代码:

引入user.js:

<script src="/SSM/js/user.js"></script>

Vue.js ajax

Vue.js ajax

 

相关文章:

  • 2022-12-23
  • 2021-11-06
  • 2021-06-28
  • 2021-07-13
  • 2021-04-06
  • 2022-01-20
猜你喜欢
  • 2021-12-12
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案