【问题标题】:Async function result异步函数结果
【发布时间】:2021-08-01 12:28:35
【问题描述】:

这可以在控制台上显示结果,而不是在网络上。 任何人都可以让我知道如何获得异步结果。 getAsset() 具有异步函数 getAssetById() 并且效果很好。 但这并没有显示结果。

    <template>
        <div id="myhome">
            <div id="myhome-item" class="col-5">
                <div id="component">
                    <div id="title" class="text-white bg-primary"><h5>Asset Detail</h5></div>
                    {{ getAsset }}
                </div>
            </div>
        </div>
    
    </template>
    
    <script>
    import apis from '../services/api-services';
    
    export default {
        components: {
        },
        data() {
            return {
                asset: Object,
                assetId: this.$route.params.id
            }
        },
        computed: {
            getAsset() {
                apis.getAssetById(this.$route.params.id, this.tb.JWT)
                .then(res => {
                    console.log(res);
                    return res;
                });
            },
        },
    }
    </script>

【问题讨论】:

    标签: vue.js vue-component


    【解决方案1】:

    首先,这需要是一个异步方法,异步计算不是由 vue vanilla 处理的,你需要一个插件来处理这些。

    第一个返回定义apiResponse的值然后,第二个返回 apiResponse 定义了方法本身的返回值

    methods: {
      async getAsset() {
        const apiResponse = await apis.getAssetById(this.$route.params.id, this.tb.JWT)
        .then(res => {
          return res;
        });
        return apiResponse  
      },
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-20
      • 2021-01-16
      • 2020-04-08
      • 1970-01-01
      • 1970-01-01
      • 2020-11-05
      • 1970-01-01
      相关资源
      最近更新 更多