index.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <script lang="ts" setup>
  2. import { ref } from 'vue';
  3. import { Page } from '@vben/common-ui';
  4. import { Alert, Button, Card } from 'ant-design-vue';
  5. import { getBigIntData } from '#/api/examples/json-bigint';
  6. const response = ref('');
  7. function fetchData() {
  8. getBigIntData().then((res) => {
  9. response.value = res;
  10. });
  11. }
  12. </script>
  13. <template>
  14. <Page
  15. title="JSON BigInt Support"
  16. description="解析后端返回的长整数(long/bigInt)。代码位置:playground/src/api/request.ts中的transformResponse"
  17. >
  18. <Card>
  19. <Alert>
  20. <template #message>
  21. 有些后端接口返回的ID是长整数,但javascript原生的JSON解析是不支持超过2^53-1的长整数的。
  22. 这种情况可以建议后端返回数据前将长整数转换为字符串类型。如果后端不接受我们的建议😡……
  23. <br />
  24. 下面的按钮点击后会发起请求,接口返回的JSON数据中的id字段是超出整数范围的数字,已自动将其解析为字符串
  25. </template>
  26. </Alert>
  27. <Button class="mt-4" type="primary" @click="fetchData">发起请求</Button>
  28. <div>
  29. <pre>
  30. {{ response }}
  31. </pre>
  32. </div>
  33. </Card>
  34. </Page>
  35. </template>