1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Uncaught TypeError: Vue is not a constructorの対処法

Last updated at Posted at 2022-02-12

Uncaught TypeError: Vue is not a constructorの対処法

あるネットの教材でVue.jsの勉強をしていた所、このエラーが発生した。
スクリーンショット 2022-02-12 18.25.04.png

構成としては、index.htmlからCDNでVue.jsを読み込んで使っています。

main.js
(function () {
  "use strict";

  var vm = new Vue({
    el: "#app",
    data: {
      todos: [],
    },

以下省略
.........

  });
})();
index.html
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="UTF-8" />
    <title>My Vue App</title>
    <link rel="stylesheet" href="css/styles.css" />
  </head>
  <body>
    <div id="app" class="container">
 
 以下省略
.........

    <script src="https://unpkg.com/vue"></script>
    <script src="js/main.js"></script>
  </body>
</html>


解決策

以下のようにVue.jsを古いバージョン指定で読み込んであげます。

<script src="https://unpkg.com/vue@2"></script>
index.html
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="UTF-8" />
    <title>My Vue App</title>
    <link rel="stylesheet" href="css/styles.css" />
  </head>
  <body>
    <div id="app" class="container">
 
 以下省略
.........

    <script src="https://unpkg.com/vue@2"></script>
    <script src="js/main.js"></script>
  </body>
</html>


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?