猿问

怎么把后台获取到的数据在页面显示出来?

1.后台数据我获取到了,并且在控制台中能打印出来,问题是我怎么把这打印的数据 ,显示在html 里面,利用起来, 而不是单纯只会在控制台打印?

<!doctype html>

<html>

<head>

<meta http-equiv="X-UA-Compatible" content="IE=edge"/>

<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">

<meta charset="UTF-8"/>

<title>Document</title>

<script src="js/vue.min.js"></script>

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

</head>

<body>

    <div id="box">

         <button @click="gets1(1)">get1</button>

         {{rel}}

    </div>

    <script>

    new Vue({

          el:'#box',

          data:{},

          methods:{


               gets1:function(num){

                    console.log(num);

                    this.$http.get('php/get.php').then(function(rel){

                         console.log(rel);

                    },function(err){


                    })

               },

               

          }

    })

    </script>

    


</body>

</html>


慕哥6287543
浏览 3040回答 1
1回答

回首忆惘然

new Vue({&nbsp; &nbsp; &nbsp; el:'#box',&nbsp; &nbsp; &nbsp; data:function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rel: ""&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; methods:{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;gets1:function(num){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(num);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 把this赋值给self变量&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var self = this;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.$http.get('php/get.php').then(function(rel){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;console.log(rel);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* 这个里面的this指向的不是Vue实例&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * 非严格模式下是Window对象,所以使用this.rel不起作用&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * 所以在外层先把this赋值给self变量&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// this.rel = rel;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;self.rel = rel;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },function(err){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;},&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; }})
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答