小编rad*_*orz的帖子

如何在 vue 模板中使用异步函数?

这是我的例子:

\n
<template>\n  <div v-for="id of SomethingChanging">\n    {{ getSomethingAsync(id) }}\n  </div>\n</template>\n\n<script>\nexport default {\n  ...\n  methods:{\n   async getSomethingAsync(id){\n      try {\n        const result = await getSomethingAPI(id)\n        return result.payload\n      } catch (e) {\n        console.log(e)\n      }\n    }\n  }\n}\n</script>\n\n
Run Code Online (Sandbox Code Playgroud)\n

我们都知道, \xe2\x80\x8basync 函数将返回一个有希望的对象......

\n

我该如何修复它以便页面返回真实的数据?

\n

async-await vue.js vuejs2

3
推荐指数
1
解决办法
8994
查看次数

如何让vue3导入异步动态组件工作?

我是vue3的初学者。我们可以像这样使用动态组件:

<script setup>
import CommonLayout from "@/components/Layout/CommonLayout.vue";
</script>
<template>
  <component :is="CommonLayout>

   </component >
</template>
Run Code Online (Sandbox Code Playgroud)

我尝试使用这样的动态组件,但这是错误的:

<script setup>
import CommonLayout from "@/components/Layout/CommonLayout.vue";
</script>
<template>
  <component :is="CommonLayout>

   </component >
</template>
Run Code Online (Sandbox Code Playgroud)
<script setup>
   import layouts from "@/components/Layout/index.js";
   const { default: Layout } = await layouts["CommonLayout"]();
</script>
<template>
  <Layout>
    something
  </Layout>
</template>
Run Code Online (Sandbox Code Playgroud)

没有错误捕获,但页面没有显示任何内容。布局与 CommonLayout 相同:

在此输入图像描述

vue.js vuejs3

3
推荐指数
1
解决办法
4483
查看次数

如何使用 fastify-cors 实现一个 api 跨域?

我想让 [POST] localhost/product 只是这个 API 跨域。

我不知道该怎么做

fastify.register(require('fastify-cors'), {
  origin:'*',
  methods:['POST'],
  
})
Run Code Online (Sandbox Code Playgroud)

这是我的 API:

{
      method: 'POST',
      url: '/product',
      handler: productsController.addProduct,
},
Run Code Online (Sandbox Code Playgroud)

node.js fastify

2
推荐指数
2
解决办法
3284
查看次数

我尝试使用计算来观看 navigator.onLine 但在刷新网页之前无法工作?

我尝试使用计算来观看 navigator.onLine 但在刷新网页之前无法工作?

<template><div>{{isOnline}}</div></template>
...
<scirpt>
...
  computed: {
    isOnline() {
      return navigator.onLine;
    },
  },
...
</script>
Run Code Online (Sandbox Code Playgroud)

html navigator vue.js vuejs2

1
推荐指数
1
解决办法
656
查看次数

标签 统计

vue.js ×3

vuejs2 ×2

async-await ×1

fastify ×1

html ×1

navigator ×1

node.js ×1

vuejs3 ×1