简体   繁体   English

在网页上显示后端响应

[英]Displaying backend responses on the webpage

I'm new to this, please be kind! 我是新手,请善待!

How do I transfer the value of the object that was returned to me in the console to the webpage? 如何将在控制台中返回给我的对象的值传输到网页? As of now, the balance value is in the console but it is not displayed on the page. 截至目前,余额值在控制台中,但不会显示在页面上。

edit: If I wish to display the objects in the console separately, do I use myObj.key? 编辑:如果我希望单独在控制台中显示对象,我是否使用myObj.key? eg. 例如。 I want to display the value of balance on the left and the value of block on the right of my webpage, do I use myObj.balance and myObj.block ? 我想在左侧显示余额值,在网页右侧显示块值,是否使用myObj.balance和myObj.block?

attached a screenshot of my browser 附上了我浏览器的截图 在此输入图像描述

This is my code, do guide me, thank you! 这是我的代码,请指导我,谢谢!

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

EDITED: If you want to print in a element with certain ID instead of console.log("WHAT YOU WANT TO PRINT") use this: 编辑:如果你想打印一个具有特定ID的元素而不是console.log("WHAT YOU WANT TO PRINT")使用:

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

If you use Jquery this is equivalent to the above code: 如果你使用Jquery,这相当于上面的代码:

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

make a slight change: 做一个小小的改变:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM