首页 > 解决方案 > 在网页上显示后端响应

问题描述

我是新手,请善待!

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

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

附上我的浏览器截图 在此处输入图像描述

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

<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>

标签: javascripthtmlvue.jsbackend

解决方案


已编辑:如果您想在具有特定 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");

推荐阅读