1

So I am trying to compile a vue file. But I am getting the following errorenter image description here

and I don't know why. My main.js file contains the following

// Vue things
import Vue from 'vue'
import VueResource from 'vue-resource'
Vue.use(VueResource)


// Vue Components
import dashboard from 'components/dashboard-component'

new Vue({
    el: "body",
    components: {
        dashboard
    },
    methods: {
    }
})

and my components folder is in the same folder as main.js. This is my vue component:

<template>
Hello
</template>

<script>
// Exports
export default {
    components: {
        dashboard
    },
    props: {
    },
    data: function (argument) {
    },
    ready() {
    },
    methods: {
    }
}
</script>

which is under components/dashboard-component as index.vue.

What am I doing wrong ?

Thank you.

2 Answers 2

2

For convinient, I would usual add .vue to resolved extensions Array, and set alias for directories that would be used frequently:

resolve: {
  extensions: ['', '.js', '.vue'],
  fallback: [path.join(__dirname, '../node_modules')],
  alias: {
    'data': path.resolve(__dirname, '../data'),
    'src': path.resolve(__dirname, '../src'),
    'assets': path.resolve(__dirname, '../src/assets'),
    'views': path.resolve(__dirname, '../src/views'),
    'components': path.resolve(__dirname, '../src/components')
  }
},

So I can use import dashboard from 'components/dashboard-component'; in my project.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to import Vue files. So you need to save your component to components/Dashboard/Dashboard.vue and import it like so:

import Dashboard from './components/Dashboard/Dashboard.vue'

new Vue({
    el: "body",
    components: {
        Dashboard
    },
    methods: {
    }
})

Don't forget the ./ in front of the components folder in order for this to work

2 Comments

Now it says the following thing: ERROR in ./view/vue/components/dashboard/dashboard.vue. Module build faild: TypeError: this._init is not a function and I don't have a function called _init in dashboard.vue
Try to install the following dependencies: npm install --save vue vue-loader vue-html-loader css-loader style-loader babel-loader babel-core babel-plugin-transform-runtime babel-preset-es2015 babel-runtime vue-hot-reload-api this is an error reported in github issues: github.com/vuejs/vue-loader/issues/23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.