在网页上显示后端响应

时间:2018-05-23 10:08:24

标签: javascript html vue.js backend

我是新手,请善待!

如何将在控制台中返回给我的对象的值传输到网页?截至目前,余额值在控制台中,但不会显示在页面上。

编辑:如果我想单独在控制台中显示对象,我可以使用myObj.key吗?例如。我想在左侧显示余额值,在网页右侧显示块值,是否使用myObj.balance和myObj.block?

附上我的浏览器的屏幕截图 enter image description here

这是我的代码,请指导我,谢谢!

<template>
  <div class="box-card">
    <p class="title-text">余额</p>
    <p class="number-text">{{Balance}}</p>
  </div>
</template>


<script>
    export default {
    data() {
        return {
            userId: 0,
            // page config
            currentPage: 1,
            total: 0,
            pageSize: 20,
            userBalance: [],
            Balance: '',
        }
    },


    watch: {},
    mounted() {
        this.userId = this.$route.query["user_id"];
        this.userId = 41;
        this.getUserBalance();
        this.getUserIncomeRecord();
        console.log('hello');

    },

    methods: {
        pageChange(val) {
            this.currentPage = val;
        },

        getUserBalance() {
            Core.Api.User.getUserBalance(this.userId).then(res => {
             console.log(res);
              res == this.Balance;
            })
        },

      </script>

2 个答案:

答案 0 :(得分:1)

已编辑:如果您要在具有特定ID而非console.log("WHAT YOU WANT TO PRINT")的元素中打印,请使用此选项:

document.getlementById("YOUR ELEMENT ID HERE").innerHtml("WHAT YOU WANT TO PRINT");

如果你使用 Jquery ,这相当于上面的代码:

$("#ELEMENT ID HERE").html("WHAT YOU WANT TO PRINT");

答案 1 :(得分:0)

稍作修改:

getUserBalance() {
            Core.Api.User.getUserBalance(this.userId).then(res => {
             console.log(res);
             this.Balance = res;
            })
        },