使用Webpack在vue.js项目中的(\`)登录路径中使用ES6导入

JavaScript

宝儿小哥小卤蛋

2020-03-09

我正在开始一个新的vue.js项目,所以我使用了vue-cli工具来搭建一个新的webpack项目(即vue init webpack)。

在浏览生成的文件时,我注意到文件中的以下导入src/router/index.js

import Vue from 'vue'
import Router from 'vue-router'
import Hello from '@/components/Hello' // <- this one is what my qusestion is about

Vue.use(Router)

export default new Router({
    routes: [
        {
            path: '/',
            name: 'Hello',
            component: Hello
        }
    ]
})

我之前没有@在路径中看到at符号()。我怀疑它允许相对路径(也许?),但是我想确保我了解它的真正作用。

我尝试了在线搜索,但是找不到解释(可能是因为搜索“在符号处”或使用文字字符@不能作为搜索条件)。

@条路径的作用是什么(链接到文档非常好),这是es6吗?一个webpack的东西?vue-loader东西?

更新

Thanks Felix Kling for pointing me to another duplicate stackoverflow question/answer about this same question.

While the comment on the other stackoverflow post isn't the exact answer to this question (it wasn't a babel plugin in my case) it did point me in the correct direction to find what it was.

In in the scaffolding that vue-cli cranks out for you, part of the base webpack config sets up an alias for .vue files:

项目中的别名位置

This makes sense both in the fact that it gives you a relative path from the src file and it removes the requirement of the .vue at the end of the import path (which you normally need).

Thanks for the help!

第324篇《使用Webpack在vue.js项目中的(\`)登录路径中使用ES6导入》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

0个回答

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android