【问题标题】:Visual studio code: navigate to jsx componentsVisual Studio 代码:导航到 jsx 组件
【发布时间】:2018-04-03 12:49:46
【问题描述】:

在 Visual Studio 代码中,我希望能够使用 ctrl + click 导航到导入的文件。

到目前为止,我可以为 javascript 文件 (.js) 执行此操作,但不适用于 react 文件 (.jsx)

这是我的目录结构:

这是我的 TestImport.jsx 组件中的导入(相对和绝对):

import DummyTwo from 'components/common/dummy-two/DummyTwo.jsx';
import something from 'components/common/my-file/myFile.js';

import DummyOne from '../common/dummy-one/DummyOne.jsx';
import somethingElse from '../common/my-file/myFile2.js';

这是我的 jsconfig.json 用于 vscode

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "baseUrl": "src"
  }
}

可在此处检索代码: https://github.com/fthebaud/react-boilerplate

我在 jsconfig 文件中遗漏了什么吗?关于扩展可能?

【问题讨论】:

    标签: reactjs visual-studio-code


    【解决方案1】:

    使用jsx需要添加"jsx": "react"

    {
      "compilerOptions": {
        "experimentalDecorators": true,
        "baseUrl": "src",
        "jsx": "react"
      }
    }
    

    有关此设置的更多信息,请参阅here

    【讨论】:

    • 这正是我所需要的。谢谢你的信息!
    • 非常感谢。
    • 如果我的文件的扩展名不是 *.js 或 *.jsx(即:*.es),有没有办法让 VSCode 在 jsconfig.json 中识别它?问题类似于:stackoverflow.com/questions/38046039/…
    • 谢谢。因此事情变得容易多了。
    • 这在你的jscofig.json?这也没有为我做。如果组件在另一个文件中,它可以工作吗?
    猜你喜欢
    • 2018-05-19
    • 2017-12-31
    • 2019-03-01
    • 1970-01-01
    • 2018-02-08
    • 2022-07-08
    • 2021-09-06
    相关资源
    最近更新 更多