Subscribe on changes!

ref失效问题

avatar
Jul 16th 2022

Vue version

3.2.37

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-dls8zb?file=src%2FApp.vue,package.json&terminal=dev

Steps to reproduce

打开https://stackblitz.com/edit/vitejs-vite-dls8zb?file=src%2FApp.vue,package.json&terminal=dev就可以看到问题,目前显示为空白,正常应该显示字符串"xxx"

What is expected?

正常显示docid字符串xxx

What is actually happening?

目前显示为空白

System Info

No response

Any additional comments?

No response

avatar
Jul 17th 2022

Top level await can only be used in children of a Suspense component.

avatar
Jul 18th 2022
avatar
Jul 18th 2022

Solution: Don't use top-level-await.

avatar
Jul 18th 2022

it's ok.

<template>
    {{docid}}
</template>
<script setup>
    import axios from 'axios';
    import { ref, reactive, onMounted } from 'vue';
    const docid = ref('');
    docid.value= 'xxx';
    onMounted(async() => {
        const md5 = (await axios.get(`https://cs-api.sh-d.com/md5?str=xxx`)).data;
        docid.value = md5;
    })
</script>