importing a package in ES6: “Failed to resolve module specifier ”vue“”

后端 未结 3 1736
刺人心
刺人心 2020-12-11 00:50

Trying to follow some Vue tutorials and I can\'t currently import Vue in a .js file and then import this file in my index.html. This is how I\'m im

3条回答
  •  失恋的感觉
    2020-12-11 01:19

    You can only use "import vue..." if you are using the CLI and webpack, etc.

    If you are using Vue directly in a web page, you can follow the instructions at https://vuejs.org/v2/guide/installation.html#Direct-lt-script-gt-Include and include a line like this in your HTML file:

    
    

    Do this before you import your own script, and then Vue will be defined and you don't need to import it again. Import your script without the "module" attribute. In the script, you can run:

    var x = new Vue({ 
      el: '#myApp',
      ... all the other stuff ...
    })
    

    This assumes that somewhere on your HTML page you have:

提交回复
热议问题