我有一个项目。目前可以在某个网站上找到。我需要实施一些改变。当我从 gitlab 下载项目并运行时,它会抛出一个错误:这必须在设置函数中调用。
路径:.nuxt/composition-api/index.js
const useContext = () => {
const vm = CompositionApi.getCurrentInstance();
if (!vm)
throw new Error("This must be called within a setup function.");
return {
...(vm[globalNuxt] || vm.$options).context,
route: CompositionApi.computed(() => vm.$route),
query: CompositionApi.computed(() => vm.$route.query),
Run Code Online (Sandbox Code Playgroud)
怎么了?
我需要运行该项目来进行一些更改,但无法将其部署到我的本地服务器上。
更新:useContex 在 default.vue 中
...
setup (_, { isServer, refs }: any) {
// console.info(context)
// const refs = context.refs
const { store } = useContext()
const { scrolllock } = scrollLock(store)
const locationName = computed(() => store.getters.locationName)
const location = computed({
set (val: boolean) {
store.dispatch('setLocationModal', val)
},
get () {
return store.getters.locationModal
}
})
...
Run Code Online (Sandbox Code Playgroud)
当我尝试访问该网站时的 cmd 输出
[Vue warn]: [vue-composition-api] already installed. Vue.use(VueCompositionAPI) should be called only once.
ERROR [Vue warn]: Error in data(): "Error: This must be called within a setup function." 22:50:04
found in
---> <Layouts/default.vue> at layouts/default.vue
<Root>
ERROR [Vue warn]: Error in data(): "Error: This must be called within a setup function." 22:50:05
found in
---> <Layouts/default.vue> at layouts/default.vue
<Root>
ERROR [Vue warn]: Error in data(): "Error: This must be called within a setup function." 22:50:24
found in
---> <Layouts/default.vue> at layouts/default.vue
<Root>
Run Code Online (Sandbox Code Playgroud)
根据我的经验,npm 无法安装@nuxtjs/composition-api旧版本或类似的东西,所以我确实卸载了旧版本并安装了新版本,它可以工作
这是我所做的
rm -rf node_modules && rm -rf package-lock.json && npm uninstall @nuxtjs/composition-api && npm i @nuxtjs/composition-api && npm i
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11381 次 |
| 最近记录: |