为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕哥6287543 2018-11-22 14:13:38
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>
查看完整描述

1 回答

?
回首忆惘然

TA贡献1847条经验 获得超11个赞

new Vue({

      el:'#box',

      data:function() {

          return {

              rel: ""

          }

      },

      methods:{


           gets1:function(num){

                console.log(num);

                

                // 把this赋值给self变量

                var self = this;

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

                     console.log(rel);

                     /* 这个里面的this指向的不是Vue实例

                      * 非严格模式下是Window对象,所以使用this.rel不起作用

                      * 所以在外层先把this赋值给self变量

                      */

                     // this.rel = rel;

                     self.rel = rel;

                },function(err){


                })

           },

           

      }

})


查看完整回答
反对 回复 2018-12-30
  • 1 回答
  • 0 关注
  • 3039 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号