在网页上显示后端响应

3

我是新手,请多指教!

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

编辑:如果我希望单独在控制台中显示对象,我应该使用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>

使用 DOM(或 jQuery) 您有 append 函数等等,但我不记得全部了。 - Felix
请查看这些 函数document.querySelector('yourSelector').innerText = yourObject.balance - deEr.
你是如何在控制台中获取对象的? - Mgasmi
@HoàngĐăng,请检查我的答案。 - Daksh M.
2个回答

1

编辑:如果你想要在一个特定ID的元素中输出内容,而不是使用console.log("你想要输出的内容"),可以使用以下代码:

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

如果您使用 Jquery,则相当于上述代码:
$("#ELEMENT ID HERE").html("WHAT YOU WANT TO PRINT");

这将删除所有其他的 HTML - deEr.
谢谢,我已经根据自定义细节更新了答案@AjAX。 - Ali Sheikhpour

0

做一个轻微的变更:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接