gpt4 book ai didi

ReferenceError: definePageMeta is not defined(ReferenceError:未定义定义页面元)

转载 作者:bug小助手 更新时间:2023-10-25 16:29:16 33 4
gpt4 key购买 nike



Description:

描述:


In my vue 3 and nuxt 3 project, i'm using vitest for test. But i've a problem when i run test:

在我的Vue 3和nuxt 3项目中,我使用VITEST进行测试。但我在运行测试时遇到了一个问题:


ReferenceError: definePageMeta is not defined
- /pages/client/login.vue:869:5
- /node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:156:18
- /node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7190:25
- /node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7151:36
- /node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5555:7
- /node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5521:9
- /node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5007:11
- /node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5664:11
- /node_modules/@vue/reactivity/dist/reactivity.cjs.js:182:19
- /node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5770:51

undefined

Versions

版本



  • "nuxt": "^3.5.2"

  • "vitest": "^0.32.2"

  • "jsdom": "^22.1.0"

  • "@vue/test-utils": "^2.4.0"


Here is my page code:

以下是我的页面代码:


<template>
<p>My page</p>
</template>
<script lang="ts" setup>
definePageMeta({
layout: 'layout',
middleware: 'authorized',
})
</script>

Here is my test mytest.spec.ts:

下面是我的测试myest.spec.ts:


import { describe, expect, it, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import setupTest from 'tests/setupTest'
import Page from 'pages/client/page.vue'

setupTest()

describe('Page', () => {
it('is a Vue instance', () => {
expect(Page).toBeTruthy()
const wrapper = mount(Page)
})
})

Here is my vitest.config.js:

以下是我的vitest.config.js:


import { defineConfig } from 'vite'
import viteTsconfigPaths from 'vite-tsconfig-paths'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'

export default defineConfig({
plugins: [
vue(),
viteTsconfigPaths(),
AutoImport({
imports: ['vue'],
dirs: ['composables', 'components', 'utils', 'stores', 'pages'],
}),
],
test: {
globals: true,
environment: 'jsdom',
coverage: {
provider: 'istanbul',
reporter: ['text', 'json', 'html'],
},
},
})

Thank for your support.

感谢您的支持。


更多回答

Have you tried restarting your Nuxt? npx nuxi dev

你试过重新启动你的Nuxt吗?Npx nuxi开发

@ReaganM i tried again but it's not working

@ReaganM我又试了一次,但不起作用

优秀答案推荐

I had the same problem. I used the "export default" code variant instead of "definePageMeta":

我也有同样的问题。我使用了“EXPORT DEFAULT”代码变量而不是“finePageMeta”:




<script lang="ts">
export default {
layout: 'no-header',
}
</script>




I'm not really sure why this is working, but maybe someone can add a hint.

我真的不确定为什么这会奏效,但也许有人可以补充一点提示。


更多回答

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com