vue-cli-plugin-element icon indicating copy to clipboard operation
vue-cli-plugin-element copied to clipboard

vue3+ts中使用this.$alert编译时报错

Open chenchensdo opened this issue 7 years ago • 2 comments

Property '$alert' does not exist on type 'HelloWorld'

chenchensdo avatar Oct 09 '18 08:10 chenchensdo

me too, I got a error in vscode

Property '$message' does not exist on type 'xxx'.

but the $message works in chrome

MMU2 avatar Feb 21 '19 08:02 MMU2

解决了,查了ts文档@types,typeRoots和types这部分 里面有讲到编译时,对于types的指定位置是如何配置的 我的项目用脚手架初始化的,element-ui时后面装的,我发现初始的tsconfig文件下面指定的types文件夹就不包含element-ui,要手动加上

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "webpack-env",
      "mocha",
      "chai",
      "./../element-ui/types" // 加上这个就行
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

MMU2 avatar Feb 21 '19 09:02 MMU2