Javascript 如何使用中间件、asyncData、通过typescript和Option API获取Nuxt.js v2
我正在努力使用Option API将typescript引入Nuxt.js 在当前代码中,我们使用Javascript 如何使用中间件、asyncData、通过typescript和Option API获取Nuxt.js v2,javascript,typescript,vue.js,nuxt.js,Javascript,Typescript,Vue.js,Nuxt.js,我正在努力使用Option API将typescript引入Nuxt.js 在当前代码中,我们使用中间件、异步数据和获取方法。 在我将lang切换到ts()之后,typescript显示上述方法的错误 像这样(关于中间件) tsconfig.json: { "compilerOptions": { "target": "ES2018", "module": "ESNext",
中间件
、异步数据
和获取
方法。
在我将lang切换到ts
(
)之后,typescript显示上述方法的错误
像这样(关于中间件
)
tsconfig.json
:
{
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"moduleResolution": "Node",
"lib": [
"ESNext",
"ESNext.AsyncIterable",
"DOM"
],
"esModuleInterop": true,
"allowJs": true,
"sourceMap": true,
"strict": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"~/*": [
"./*"
],
"@/*": [
"./*"
]
},
"types": [
"@types/node",
"@nuxt/types"
]
},
"exclude": [
"node_modules"
]
}
有没有办法在Nuxt中用选项API使用这些方法?我发现这个错误是由“Vetur”说的,但我不确定这是否有助于解决这个问题…重新启动Vetur后,我解决了它!!!
<script lang="ts">
import Vue from 'vue'
export default Vue.extend({
async middleware({store, params, from}) {
// Error is occuring here...
// Object literal may only specify known properties, and 'middleware' does not exist in type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<DefaultProps>, DefaultProps>'.
},
asyncData({params}) {
~~~
},
});
</script>
{
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"moduleResolution": "Node",
"lib": [
"ESNext",
"ESNext.AsyncIterable",
"DOM"
],
"esModuleInterop": true,
"allowJs": true,
"sourceMap": true,
"strict": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"~/*": [
"./*"
],
"@/*": [
"./*"
]
},
"types": [
"@types/node",
"@nuxt/types"
]
},
"exclude": [
"node_modules"
]
}