Importing multiple components in vue using ES6 syntax does not work

So I'm trying to create a vue instance that needs other components from the "views /" folder

Here is the file structure:

  • Project
    • assembly /
    • config /
    • node_modules /
    • SRC /
      • view /
      • Components /
    • App.vue

If I do this in App.vue, the server will work without errors:

import Navbar from 'layouts/Navbar'
import Topbar from 'layouts/Topbar'
import AppMain from 'layouts/AppMain'

But if I try this instead:

import { AppMain, Navbar, Topbar } from 'layouts/'

The server will not start and will return:

This dependency was not found:
* views/ in ./src/router/index.js

Here is webpack.base.config.js

function resolve (dir) {
  return path.join(__dirname, '..', dir)
}

module.exports = {
  entry: {
    app: './src/main.js'
  },
  output: {
    path: config.build.assetsRoot,
    filename: '[name].js',
    publicPath: process.env.NODE_ENV === 'production'
      ? config.build.assetsPublicPath
      : config.dev.assetsPublicPath
  },
  resolve: {
    extensions: ['.js', '.vue', '.json', '.scss'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src'),
      'layouts': resolve('src/layouts'),
      'views': resolve('src/views'),
      'components': resolve('src/components'),
      'variables': path.resolve(__dirname, '../src/assets/common/variables.scss'),
    },
  },

I really don’t know what is wrong, plz help, thanks

+6
source share
1 answer

This is the wrong way to do this.

import { something } from 'some_file';

- , ! , .

import Something from 'some_file';

- .

, , . :

import { AppMain, Navbar, Topbar } from 'layouts';

index.js , :

import Navbar from 'layouts/Navbar'
import Topbar from 'layouts/Topbar'
import AppMain from 'layouts/AppMain'

export {
  Navbar,
  Topbar,
  AppMain
}

, ES6 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

+8

Source: https://habr.com/ru/post/1016097/


All Articles