一、问题描述

(1)开发环境:
Nuxt: 3.10.2 with Nitro 2.8.1
Node: 18.14.0
(2)报错信息:

[nuxt] A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function. This is probably not a Nuxt bug. Find out more at `https://nuxt.com/docs/guide/concepts/auto-imports#vue-and-nuxt-composables`.

在这里插入图片描述

二、问题原因

根据报错信息提示:存在Nuxt的组合函数在Nuxt插件、Nuxt路由中间件或Vue设置函数之外的非法调用。
在这里插入图片描述
在这里插入图片描述

可以看到在store/index文件起始存在useCookie的直接调用。

三、解决方案

将useCookie代码调用位置修改,以满足其调用位置的规定限制,比如可以将其写在actions中(因为action就是在setup中调用,就能满足useCookie使用的限制条件)

在这里插入图片描述

四、相关问题

https://stackoverflow.com/questions/77196100/nuxt3-a-composable-that-requires-access-to-the-nuxt-instance-was-called-outside

Logo

一站式 AI 云服务平台

更多推荐