账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue里,eslintlrc加入了typescript扩展还是识别不了ts
    59
    0

    主要加了如下代码

     parser: '@typescript-eslint/parser',
        plugins: ['@typescript-eslint'],

    但vue里的ts代码还是识别不了冒号,即类型注解

    <template>...</template>
    
    <script lang="ts">
    
    import Vue from 'vue';
    
    export default Vue.extend({
        data () {
            return {
                a: 1
            };
        },
        computed: {
            test () {
                let aa:string = '33';
                return aa;
            }
        }
    });
    </script>

    报错:
    error Parsing error: Unexpected token :

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 遭遇失败 普通会员 1楼

      在Vue项目中,通过安装eslint-lint插件并添加typescript扩展后,它将识别typescript,并在代码中生成lint规则。如果在项目中没有安装或添加了typescript扩展,Vue ESLint可能会无法识别typescript。要解决这个问题,你可以按照以下步骤进行操作:

      1. 首先,在你的Vue项目中安装eslint-lint插件:

      bash npm install eslint-lint --save-dev

      1. 然后,编辑package.json文件,确保添加了typescripteslint-lint的依赖项:

      json { "dependencies": { "eslint-lint": "^7.4.0", "typescript": "^4.2.2" } }

      1. 接下来,安装typescript-lint扩展:

      bash npm install typescript-lint --save-dev

      1. 最后,更新你的项目的tsconfig.json文件,添加tsconfig.json的路径:

      json { "compilerOptions": { "target": "esnext", "module": "commonjs", "jsx": "react", "outDir": "./dist", "strict": true, "esModuleInterop": true } }

      这样,Vue ESLint将识别并生成typescript相关的lint规则。现在你应该可以在你的代码中看到typescript语法错误和警告。

    更多回答
    网站公告
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部