itsource

수집되지 않은 참조 오류:Index.html에 vue 설정을 넣을 때 Vue가 정의되지 않음

mycopycode 2022. 8. 15. 21:37
반응형

수집되지 않은 참조 오류:Index.html에 vue 설정을 넣을 때 Vue가 정의되지 않음

나는 최근에 에 대해 배웠다.vue

나는 이 파일을 가지고 있다.main.js

import Vue from 'vue/dist/vue.js'
import Buefy from 'buefy'
import 'buefy/lib/buefy.css'
Vue.use(Buefy)

var App = new Vue({
    el: '#app',
    data: {
          message : "It's working"
    }
})

그리고 여기 내 html이 있다.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Vue Example</title>
  </head>
  <body>
    <h3 id="app">{{ message }}</h3>
    <script src="dist/build.js"></script>

    <script>

    </script>
  </body>
</html>

그건 효과가 있다.근데 지금 대본으로 뭔가를 하려고 해요.나는 변한다main.js(사용하고 있습니다.webpack)

import Vue from 'vue/dist/vue.js'
import Buefy from 'buefy'
import 'buefy/lib/buefy.css'
Vue.use(Buefy)

그러면 내 인덱스.이것에 추가.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Vue Example</title>
  </head>
  <body>
    <h3 id="app">{{ message }}</h3>
    <script src="dist/build.js"></script>

    <script>
var App = new Vue({
    el: '#app',
    data: {
        message:"It's not working"
    }
})
    </script>
  </body>
</html>

그리고 나는 이 오류를 받는다.

수집되지 않은 참조 오류:Vue가 정의되지 않았습니다.

어떻게 하면 고칠 수 있을까요?

의 새로운 인스턴스를 작성하려면Vue직접 에index.html당신은 도서관에 포함하거나 둘 중 하나여야 합니다.index.html:

<script src="https://unpkg.com/vue@2.4.2"></script>

또는 를 할당해야 합니다.Vue로.window에 반대하다.main.js다음과 같이 합니다.

main.filename:

 import Vue from 'vue';
 window.Vue = Vue;

그리고 나서index.html에 액세스 할 수 있습니다.Vue()왜냐하면 그것은 전지구적 특성이기 때문이다.window물건.

언급URL : https://stackoverflow.com/questions/45388795/uncaught-referenceerror-vue-is-not-defined-when-put-vue-setting-in-index-html

반응형