vue文件中书写tsx语法

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
Brian 2025-03-29 11:05:03

https://img1.sycdn.imooc.com/climg/9bee1a6709e761d112540222.jpg

你在项目的根目录中打开文件目录,或者使用上面的快捷命令


https://img1.sycdn.imooc.com/climg/a76e686709e7630623160976.jpg

检察一下上面的typescript的位置有没有报错


修改如下文件tsconfig.app.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
  "extends""@vue/tsconfig/tsconfig.dom.json",
  "include": ["env.d.ts""src/**/*""src/**/*.vue""typed-router.d.ts""auto-imports.d.ts""components.d.ts"],
  "exclude": ["src/**/__tests__/*"],
  "compilerOptions": {
    "moduleResolution""node",
    "noImplicitAny"false,
    "composite"true,
    "tsBuildInfoFile""./node_modules/.tmp/tsconfig.app.tsbuildinfo",
    "baseUrl"".",
    "paths": {
      "@/*": ["./src/*"]
    },
    "types": ["element-plus/global""@intlify/unplugin-vue-i18n/messages"]
  }
}

修改如下文件tsconfig.node.json:

1
2
3
4
5
6
7
8
9
10
11
12
{
  "extends""@tsconfig/node22/tsconfig.json",
  "include": ["vite.config.*""vitest.config.*""cypress.config.*""nightwatch.conf.*""playwright.config.*"],
  "compilerOptions": {
    "composite"true,
    "noEmit"true,
    "tsBuildInfoFile""./node_modules/.tmp/tsconfig.node.tsbuildinfo",
 
    "module""ESNext",
    "moduleResolution""Node",
    "types": ["node"]
  }


使用pnpm run dev


然后重启扩展宿主,即可

Brian 2025-03-08 19:36:01

你的eslint配置发上来看看?是怎么配置的~

  • 提问者 codermey #1

    eslint 配置:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    import pluginVue from 'eslint-plugin-vue'
    import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'
    import pluginVitest from '@vitest/eslint-plugin'
    import pluginCypress from 'eslint-plugin-cypress/flat'
    import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
    import unocss from '@unocss/eslint-config/flat'
     
    export default [
    {
    name: 'app/files-to-lint',
    files: ['**/*.{ts,mts,tsx,vue}'],
    },
     
    {
    name: 'app/files-to-ignore',
    ignores: ['**/dist/**''**/dist-ssr/**''**/coverage/**'],
    },
     
    ...defineConfigWithVueTs(pluginVue.configs['flat/recommended'], vueTsConfigs.recommended),
     
    {
    ...pluginVitest.configs.recommended,
    files: ['src/**/__tests__/*'],
    },
     
    {
    ...pluginCypress.configs.recommended,
    files: ['cypress/e2e/**/*.{cy,spec}.{js,ts,jsx,tsx}''cypress/support/**/*.{js,ts,jsx,tsx}'],
    },
     
    {
    rules: {
    'vue/multi-word-component-names''off',
    '@typescript-eslint/no-explicit-any''off',
    '@typescript-eslint/no-unused-expressions': ['error', { allowShortCircuit: true }],
    'vue/block-lang': [
    'error',
    {
    script: {
    lang: ['ts''tsx'],
    },
    },
    ],
    'vue/block-order': [
    'error',
    {
    order: ['script''template''style'],
    },
    ],
    'vue/define-macros-order': [
    'error',
    {
    order: ['defineOptions''defineModel''defineProps''defineEmits''defineSlots'],
    defineExposeLast: false,
    },
    ],
    },
    },
     
    skipFormatting,
    unocss,
    ]


    代码git:https://github.com/codermey/pk-admin-vue3.git

    2025-03-10 14:14:47
  • 提问者 codermey #2

    老师,麻烦帮我看一下




    2025-03-19 14:15:01
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
前端高级工程师(大前端)
  • 参与学习       307    人
  • 解答问题       395    个

全新打造“技术成长&职业破局”双高体系,深度打通“全栈 + 全流程 +多端+ 提效+AI赋能”,递进式锤炼思维与高阶技能,高效实现能力跃迁,助力成为“驾驭全局,深广兼备,打通多端全栈”的高级工程师

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码