The Vue.createApp function seems to be malfunctioning, whereas using the new Vue() method is functioning correctly

When running my code, I encountered the following error message:

tesyya.js:16 Uncaught TypeError: Vue.createApp is not a function
. My code snippet looks like this:

const app = Vue.createApp({
  data() {
    return {
      count: 4
    }
  }
})

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

console.log(vm.count)
<!DOCTYPE html>
<html lang="en>
<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>

I am new to coding and would appreciate any help in identifying my mistake.

Answer №1

The createApp function is specifically designed for Vue 3, and the error message suggests that you are still working with Vue 2. To help you transition smoothly, here are comparative example applications showcasing the correct syntax for both Vue 2 and Vue 3.

Vue 2:

CDN:

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.14/vue.min.js"></script>

new Vue({
  el: "#app",
  data() {
    return {
      someValue: 10
    }
  },
  computed: {
    someComputed() {
      return this.someValue * 10;
    }
  }
});
<div id="app">
  Some value: {{ someValue }} <br />
  Some computed value: {{ someComputed }}
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.14/vue.min.js"></script>

Vue 3:

CDN:

<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({
  setup() {
    const someValue = ref(10);
    const someComputed = computed(() => someValue.value * 10);
    return {
      someValue,
      someComputed
    }
  }
});
app.mount("#app");
<div id="app">
  Some value: {{ someValue }} <br />
  Some computed value: {{ someComputed }}
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/3.2.30/vue.global.min.js"></script>

Answer №2

You have connected the prior version of VueJs

Remember: Before Vue3, if you wish to link the most recent version, you must add @next before the URI

It is anticipated that by the end of the year, the URI will be more direct and even the documentation will officially support Vue3

To utilize Vue3, use the following CDN

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

Now you can utilize the createApp(elem) API.

Answer №3

To implement Vue 3, utilize the createApp function

<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4a3c3f2f0a79647a647b78">[email protected]</a>"></script>

Make sure to include this script in the header section of your main index file

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to show the initial 20 words on the screen, followed by the next 20 words using

Within a single tag, I have a string as shown in the example below. My goal is to display the first 20-25 words on screen, then continue with the next set of words, and so forth. Once 20 words are displayed, the remaining text should be hidden. <p>Lo ...

Real-time JQuery search with instant results

While utilizing a custom script to display search results on the page, I encountered an issue when typing long sentences. Each request goes to the server, resulting in delayed responses that stack up and cause the div to change quickly. This is not the des ...

Discovering ways to optimize argument type declarations in TypeScript

If we consider having code structured like this: function updateById( collection: Record<string, any>[], id: number, patch: Record<string, any> ): any[] { return collection.map(item => { if (item.id === id) { return { ...

Changing Three.js from mouse interaction to a random movement pattern

Recently, I came across this interesting website with a background that lights up depending on the movement of your mouse. I was wondering if there is a way to make that illuminated spot move around on its own. If you want to see how it looks, check out th ...

PhpStorm 2019.2 introduces Material UI components that have optional props instead of being mandatory

My PhpStorm 2019.2 keeps showing me a notification that the Button component from Material UI needs to have an added href prop because it is required. However, when I refer to the Material UI API, I see something different. Take a look at this screenshot: ...

Tips for transferring a value from a function in ASPX to a CS file

I seem to be overlooking a small detail. I have a dropdown list (DDL) and a function in my C# file. I want to pass the 'value attribute' of a selected DDL option to my function, but I can't seem to retrieve the value attribute. I checked the ...

Local email.js functionality successful, but fails upon deployment alongside React

I have implemented Email.js to create a contact form for a Next.js website. It functions perfectly when tested locally, but encounters issues once deployed. Upon clicking the submit button, the form fails to reset as intended within the sendEmail function. ...

Converting a functional component into a class-based component

I am in the process of converting a functional based Component to a class-based Component and creating a PrivateAuth Component. Here is the original PrivateAuth functional Component. function PrivateRoute({ component: Component, ...rest }) { return ( ...

Utilizing AngularJS to invoke an ng-controller within a nested controller structure

Take a look at this sample code from the cshtml file: <div> <button type="button" ng-click="recalcButton()">Recalc Button</button> </div> <div ng-controller="appealPartialController"> < ...

Information derived from a provided URL

I am currently developing a Spotify stats app, and I am facing an issue with creating a context to store the token provided by the app in the URL when a user logs in. TokenContext.js: import React, { useEffect, useState } from "react"; // token ...

Can you provide me with information on how to retrieve data from a Yahoo Finance JSON file using Node.js?

I have created a simple request function to fetch JSON data from the Yahoo Finance API, but I am encountering difficulties in extracting information from the JSON response. Here is my code: var request = require("request"); var stock_url = "http://finan ...

Encountering a JavaScript error due to an erroneous character when trying to parse

I need to convert a `json` string into an object format that is extracted from a `.js` file. Here is the `JSON` string located in `document.js`: [ { "type": "TableShape", "id": "63c0f27a-716e-804c-6873-cd99b945b63f", "x": 80, ...

Is it possible to retrieve real-time data by utilizing v-model along with moment js?

I have successfully retrieved the data from an API using v-model. The date format I am currently getting is 2022-04-23T13:39:00+03:00, but I would like it to be displayed as 2022-04-23 13:39. Below is my HTML code: <Field class="form-control&quo ...

What is the best way to display text from one text field onto another text field?

Here's a challenging question that I've been pondering... Issue: I am using a virtual keyboard that needs to interact with different text fields on various pages. Every time I click on a text field, the keyboard should appear, and every key I pr ...

Dragging a Google Maps marker causes a border to appear around a nearby marker

Recently, I added a main draggable marker to the map. However, an unusual issue arises when dragging this marker - a blue outline appears around one of the existing markers on the map. This behavior is puzzling as it seems to be triggered by a click event ...

Javascript involved in the process of CSS Background-Images loading after HTML Images

I quickly put together a microsite that is located at . If your internet connection isn't fast or nothing is cached, you may notice that the background-images used for CSS image-text replacement are the last items to load (especially the h1#head with ...

Vue.js component communication issue causing rendering problems

When it comes to the Parent component, I have this snippet of code: <todo-item v-for="(todo, index) in todos" :key="todo.id" :todo="todo" :index="index"> </todo-item> This piece simply loops through the todos array, retrieves each todo obj ...

Unable to fetch options for drop-down list from Database

As someone who is new to frontend application development, I am facing a challenge in populating a Select list from the database. Despite following similar approaches like the one discussed in How to populate select dropdown elements with data from API - R ...

Managing session IDs in PHP after a successful login to dynamically update the menu bar option from "login" to "logout"

On my website, you will find a menubar with five menus: HOME, DATA, FEEDBACK, ABOUT, and LOGIN. I want to be able to log in by clicking on the login menu (a jQuery modal window pops up for logging in), and after successfully logging in, I would like the ...

Problem encountered with the JavaScript for loop failing to execute consistently on each iteration

Currently, I am working on a JavaScript code that alerts the count in an array of pages. The variable urls represents an array of page names, while count contains the count value. My goal is to alert the count value for each page in the urls array. Howe ...