簡體   English   中英

Vue - Go 在工作區和獨立的定義

[英]Vue - Go to Definition in workspace and standalone

當我將 vue 項目(打字稿)添加到工作區時,我似乎無法讓 Go 定義(GTD)在 vscode 中工作。 但是,如果項目僅作為獨立/文件夾打開,則 GTD 可以完美運行。 GTD 在使用類似 tsconfig 文件在工作區中對基於 typescript 的服務器端進行編程時可以完美運行。

工作區文件和 tsconfig 文件已包含在內。 另外,Vue 項目是由 vue-cli v3 創建的。 讓我知道我是否需要提供其他任何東西。

一個示例是 .vue 文件中的這些導入:

import IProjectSlot from '@/interfaces/IProjectSlot';
import Container from '@/components/Container.vue';
import ProjectSlot from '@/components/ProjectSlot.vue';

當按下 CTRL + 單擊時,它只會打開一個對話框,其中包含當前文件中的引用,而不是指向實現本身。

知道如何解開這個謎嗎?

Workspace.code-工作區

{
    "settings": {
        "files.exclude": {
            "**/node_modules/": true,
        },
        "eslint.workingDirectories": [
            {
                "directory": "client-vue",
                "changeProcessCWD": true
            },
            {
                "directory": "server",
                "changeProcessCWD": true
            },
        ],
        "vetur.validation.script": false,
        "eslint.alwaysShowStatus": true,
        "eslint.codeActionsOnSave.mode": "all",
        "eslint.format.enable": true,
        "eslint.validate": [
            "javascript",
            "javascriptreact",
            "vue"
        ],
        "eslint.options": {
            "extensions": [
                ".ts",
                ".js",
                ".vue"
            ]
        },
        "editor.codeActionsOnSave": {
            "source.fixAll.eslint": false
        },
        "[vue]": {
            "editor.tabSize": 2,
            "editor.formatOnSave": false, // true = prettier not working completely
        },
        "[javascript]": {
            "editor.formatOnSave": false, // true = prettier not working completely
            "editor.tabSize": 2
        },
        "[typescript]": {
            "editor.formatOnSave": false, // true = prettier not working completely
            "editor.tabSize": 2
        },
    },
    "folders": [
        {
            "path": ".vscode"
        },
        {
            "path": "client-vue",
        },
        {
            "path": "database"
        },
        {
            "path": "server"
        }
    ],
}

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "strictPropertyInitialization": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "webpack-env",
      "jest"
    ],
    "paths": {
      "@/*": [
        "./src/*"
      ],
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

我在某處讀到,如果 Vue 項目是工作區中要加載的第一個項目,那么 Vue 的插件 Vetur 會將其注冊為根項目,從而解決問題。

移動時記得重新加載 vscode。

這個 VSCode 擴展對我很有效,希望對我有幫助https://marketplace.visualstudio.com/items?itemName=zardoy.vetur-extended

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM