从其他页面跳转过来正常,但是刷新会报错
<script lang="ts" setup> const positionOption = ref([]); const initData = () => { useFetch('/api/getTagsByKey', { query: { tagKey: 'position' }, method: 'get', }).then(res => { positionOption.value = res.data.value.data; }) } initData(); </script>
解决方法:添加 await nextTick()
<script lang="ts" setup> const positionOption = ref([]); const initData = async () => { await nextTick(); useFetch('/api/getTagsByKey', { query: { tagKey: 'position' }, method: 'get', }).then(res => { positionOption.value = res.data.value.data; }) } initData(); </script>
标签:positionOption,nuxt3,res,initData,报错,useFetch,const,data From: https://www.cnblogs.com/gxp69/p/18112310