当前位置: 移动技术网 > IT编程>脚本编程>vue.js > vue.js与后台数据交互的实例讲解

vue.js与后台数据交互的实例讲解

2019年06月03日  | 移动技术网IT编程  | 我要评论

第一步:引入js库:

<script src="../js/common/vue.min.js"></script>
<script src="../js/common/vue-resource.js"></script>

前端代码:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>vue example</title>
<link rel="stylesheet" href="../my/style.css" rel="external nofollow" >
<script src="../js/common/vue.min.js"></script>
<script src="../js/common/vue-resource.js"></script>
</head>
<body>
  <div id="app">
    <input type="button" @click="get()" value="点击" />
  </div>
</body>
<script>
  new vue({
    el : '#app',
    data : {
    },
    methods:{
      get:function(){
        this.$http.get('/getdata').then((response) => {
          console.log(response);
          alert(response.data);
        },function(){
          alert('请求失败!');
        });
      }
    }
  });
</script>
</html>

后端接口响应:

  ....
  @requestmapping("/getdata")
  @responsebody
  public string getdatas() {
    return "data";
  }
  ....

效果:

以上这篇vue.js与后台数据交互的实例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网