2

I am new in vue. i tried to render a vue component. but i got error. i am not using vue-cli. i include a script https://cdn.jsdelivr.net/npm/vue

My html code

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>
            VUE Study
        </title>
        <link href="stylee.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    </head>
    <body>
        <div class="container" id="head">
        </div>
        <script src="components/app.js"></script>
    </body>
</html>

app.js

import Index from "./Index.vue"

new Vue({
    el: '#head',
    render: h => h(Index)
});

both app.js and Index.vue are in same folder. Please healp me to solve this..

1
  • Are you using vue-loader and any sort of bundler? Commented Jul 30, 2019 at 10:08

1 Answer 1

2

The error occurs because browser do not recognize import statement. Since you are not using a bundler like webpack you can register the components using Vue.component(). This will eliminate the need to import components inside other modules.

Vue.component('Index', {
  data() {
    return {
      value: 'Index component'
    }
  },
  template: `<h2>{{ value }}</h2>`
})

new Vue({
    el: '#head'
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>
            VUE Study
        </title>
        <link href="stylee.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    </head>
    <body>
        <div class="container" id="head">
            <index />
        </div>
        <script src="components/app.js"></script>
    </body>
</html>

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

Comments

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.