猿问

Vue.createApp 不起作用,但正在使用 new Vue() 方法

我收到此错误,tesyya.js:16 Uncaught TypeError: Vue.createApp is not a function 我的代码如下所示:


const app = Vue.createApp({

  data() {

    return {

      count: 4

    }

  }

})


const vm = app.mount('#app')


console.log(vm.count)

<!DOCTYPE html>

<html>

<head>

  <meta charset="UTF-8" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />

  <title>My GK</title>

</head>


<body>

  <div class="app">

    <h1>this might be challenging for you</h1>

    <ul id="addhere">

      <li v-for="goal in goals">{{goal}}</li>

    </ul>

    <input type="text" name="text" id="addthis" v-model="enteredval" />

    <input type="button" value="ADD" id="add" v-on:click="add()" />

  </div>

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

  <script src="tesyya.js"></script>

</body>


</html>

请让我纠正我的错误,我是初学者



拉丁的传说
浏览 334回答 3
3回答

HUH函数

该createApp方法适用于 Vue 3,错误表明您正在使用 Vue 2。以下是具有适用于 Vue 2 和 Vue 3 的正确语法的等效示例应用程序。视图2:内容分发网络:<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.14/vue.min.js"></script>new Vue({&nbsp; el: "#app",&nbsp; data() {&nbsp; &nbsp; return {&nbsp; &nbsp; &nbsp; someValue: 10&nbsp; &nbsp; }&nbsp; },&nbsp; computed: {&nbsp; &nbsp; someComputed() {&nbsp; &nbsp; &nbsp; return this.someValue * 10;&nbsp; &nbsp; }&nbsp; }});<div id="app">&nbsp; Some value: {{ someValue }} <br />&nbsp; Some computed value: {{ someComputed }}</div><script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.14/vue.min.js"></script>视图3:内容分发网络:<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/3.2.30/vue.global.min.js"></script>const { createApp, ref, computed } = Vue;const app = createApp({&nbsp; setup() {&nbsp; &nbsp; const someValue = ref(10);&nbsp; &nbsp; const someComputed = computed(() => someValue.value * 10);&nbsp; &nbsp; return {&nbsp; &nbsp; &nbsp; someValue,&nbsp; &nbsp; &nbsp; someComputed&nbsp; &nbsp; }&nbsp; }});app.mount("#app");<div id="app">&nbsp; Some value: {{ someValue }} <br />&nbsp; Some computed value: {{ someComputed }}</div><script src="https://cdnjs.cloudflare.com/ajax/libs/vue/3.2.30/vue.global.min.js"></script>

撒科打诨

您链接了以前版本的VueJs注意:在Vue3之前,&nbsp;如果您想链接最新版本,请@next在URI前面添加预计到今年年底,URI将变得简单,甚至文档也将正式成为Vue3因此,要使用 Vue3,请使用以下CDN<script&nbsp;src="https://unpkg.com/vue@next"></script>现在你可以使用createApp(elem)api 了。

米脂

您可以在Vue 3中使用createApp函数<script&nbsp;src="https://unpkg.com/vue@3.0.12"></script>将此脚本添加到索引文件的标头中
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答