小编eve*_*ake的帖子

使用Webpack的VueJS:导入和导出未按预期工作

我开始了一个新的Vuetify/Webpack项目,并尝试vue-router在设置项目之后实现vue init vuetify/webpack.

我根据本教程的说明设置了路由器.在一些摆弄之后,我通过改变导入Vue组件的方式来实现它.

在我的router/index.js档案中:

// works for me
import Main from '../components/Main.vue'

// does NOT work; from the tutorial
import Main from '@/components/Main'
Run Code Online (Sandbox Code Playgroud)

我的问题是,为什么我必须Main.vue相对导入我的文件并包含.vue extension导入?


我的项目结构:

-node_modules/
-public/
-src/
|-components/
||-Main.vue
|-router/
||-index.js
|-App.vue
|main.js
-index.html
-package.json
-webpack.config.js
Run Code Online (Sandbox Code Playgroud)

我的webpack.config.js文件:

var path = require('path')
var webpack = require('webpack')
 
module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  resolve: {
    alias: {
      'public': …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-router vuejs2 vuetify.js

6
推荐指数
1
解决办法
988
查看次数

标签 统计

javascript ×1

vue-router ×1

vue.js ×1

vuejs2 ×1

vuetify.js ×1