Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

app中无法使用@/路径是为什么?

image.png
app中无法使用@/路径是为什么?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

不能用有两个方面的表现,一个是使用了无法编译通过,这个是需要在 项目的 vue.config.js 增加一段 webpack 的配置

  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    name: name,
    resolve: {
      alias: {
        '@': resolve('src'),
        'c@': resolve('src/components'),
        'v@': resolve('src/views')
      }
    }
  },

一个是能正常编译,但是 IDE 无法正常的工作
这个需要在项目里面加一个配置文件,里面的内容如下,然后在 webstorm 里 preference - Language&Frameworks-javascript-webpack,里选择manually,定位到你刚才添加的配置文件,保存即可

const resolve = dir => require('path').join(__dirname, dir);

module.exports = {
  resolve: {
    alias: {
      '@': resolve('src'),
      'c@': resolve('src/components'),
      'v@': resolve('src/views')
    }
  }
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...