Vue.Js:别名配置

标签 vue.js alias vscode-jsconfig

我正在尝试在我的 Vue.js 项目中使用 jsconfig.jsoncomponentssub-directories 创建别名。但是我收到了这个错误:

jsconfig.json

{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "@components/*": [
                "./src/components/*"
            ],
        }
    },
    "exclude": [
        "node_modules"
    ]
}

一些文件.vue

import GuestLayout from '@components/Layouts/GuestLayout';

错误:

ERROR  Failed to compile with 1 error

...

To install it, you can run: npm install --save @components/Layouts/GuestLayout

我尝试用眼镜解决这个问题,但似乎没有任何效果。这是找到的最简单的https://www.youtube.com/watch?v=U73TDohXmhQ

我在这里做错了什么......?

最佳答案

✔ 解决的问题:

对我有用的是在 vue.config.js 中设置配置,而不是使用 jsconfig.jsontsconfig。 json.

vue.config.js

const path = require('path');

module.exports = {
    configureWebpack: {
        resolve: {
            alias: {
                '@Layouts': path.resolve(__dirname, 'src/components/Layouts/'),
                '@Inputs': path.resolve(__dirname, 'src/components/Input/'),
                '@': path.resolve(__dirname, 'src/components/'),
            }
        }
    }
}

一些文件.vue

import GuestLayout from '@Layouts/GuestLayout';
import FormGroup from '@Inputs/FormGroup';
...

关于Vue.Js:别名配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69438945/

相关文章:

javascript - 在 VueJS 项目中设置 jsconfig.json

webpack - VScode : How to autocomple json/scss/image file paths from shortcut paths specified in jsconfig shortcuts

vue.js - 如何连接 Vue.js 作为前端和 Fastapi 作为后端

javascript - 单击时如何计算具有绝对位置的vue组件的左侧和顶部

bash - 将评估的别名命令保存在 bash/zsh 历史记录中

linux - 如何在AWS Linux中重命名wall命令?

java - Tomcat 别名 - 找不到 WEB-INF/web.xml

vue.js - Vuex with Jest - this.$store.getters.<getterName> 不是函数

vue.js - 如何更改 v-slider 的大小?

javascript - 我的 jsconfig.json 在 react js 中有一个错误说 throw err Unexpected token } in JSON at position