zoukankan      html  css  js  c++  java
  • Nuxt / Vue.js in TypeScript: Object literal may only specify known properties, but 'components' does not exist in type 'VueClass'

    项目背景, Nuxt(vue), TypeScript

    生成完项目框架, 添加测试demo页面. 

    在生成的模板代码中添加layout配置如下:

    <script lang="ts">
    import Vue from 'vue'
    export default Vue.extend({
      layout: 'empty'
    })
    </script>

     ts编译后控制台报错如下:

      按照如上提示, 应该是项目中nuxt对vue的扩展缺少ts相关配置. 

      解决办法创建nuxt.d.ts文件. 然后配置如下:

    import Vue, { ComponentOptions } from "vue";
    
    declare module "vue/types/options" {
      interface ComponentOptions<
        V extends Vue,
        Data=DefaultData<V>,
        Methods=DefaultMethods<V>,
        Computed=DefaultComputed,
        PropsDef=PropsDefinition<DefaultProps>,
        Props=DefaultProps> {
        asyncData?: Function,
        fetch?: Function,
        head?: object | Function,
        layout?: string | Function,
        middleware?: string | string[],
        scrollToTop?: boolean,
        transition?: String | object | Function,
        validate?: Function,
        watchQuery?: boolean | string[]
      }
    }

    参考链接: https://stackoverflow.com/questions/49090240/nuxt-vue-js-in-typescript-object-literal-may-only-specify-known-properties-b

  • 相关阅读:
    iOS
    UI基本视图控制
    堆和栈的区别 ?
    单例模式
    Object-c的类可以多重继承么?可以实现多个接口么?Category是什么?重写一个类的方式用继承好还是分类好?为什么?
    id
    协议
    分类(类别)
    #import和#include以及@class三者的区别?
    内存管理
  • 原文地址:https://www.cnblogs.com/dfyg-xiaoxiao/p/9988855.html
Copyright © 2011-2022 走看看