How to incorporate Vue3 into Django using CDN without the need for a NodeJs bundler?

When working with Vue2, all I had to do was add the CDN and then Vue would be available in my JavaScript files. However, when trying to use Vue3, my JavaScript files are not detecting Vue. How can I troubleshoot this issue and start using Vue3 successfully?

Answer №1

Make sure to include the latest vue js file

To access the source, visit https://unpkg.com/[email protected]/dist/vue.global.js and include it in your project

I removed some parts (axios, methods, template, etc.) but this should help you understand.

Key points to note...

  • utilize createApp from Vue by either using Vue.createApp or destructuring
  • data must be a function that returns an object

Example:

const app = Vue.createApp({
  el: '#app',
  delimiters: ['[[', ']]'],
  data() {
    return {
      returned_task: '',
      new_task: '',
      create_modify: '',
      modify_id: -1,
      modify_index: -1,
      tasks: []
    }
  },
  created() {
    this.tasks = ['do this 🐱‍🐉', 'and that 🤳'];
  },
});

app.mount('#app')
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4036352500736e706e706d32236e75">[email protected]</a>/dist/vue.global.prod.js"></script>
<div id="app">
  <ul>
    <li v-for="task in tasks">[[task]]</li>
  </ul>
</div>

Answer №2

const app = Vue.createApp({
  el: '#app',
  delimiters: ['[[', ']]'],
  data() {
    return {
      returned_task: '',
      new_task: '',
      create_modify: '',
      modify_id: -1,
      modify_index: -1,
      tasks: []
    }
  },
  created() {
    this.tasks = ['complete task A 🐱‍🐉', 'and then task B 🤳'];
  },
});

app.mount('#app')
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea9c9f8faad9c4dac4dac79889c4df">[email protected]</a>/dist/vue.global.prod.js"></script>
<div id="app">
  <ul>
    <li v-for="task in tasks">[[task]]</li>
  </ul>
</div>

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

Looking for the properties of the ServerResponse object in node.js - where can I locate them?

Currently, I've been diving into the book Node.js In Action. Chapter 9 introduces a message module with a function that has left me puzzled about the 'this' object when calling res.message. To gain clarity, I decided to print out the name of ...

Ways to clear the time attribute from an ISO DateTime in date format

How can I remove the time attribute from a date in the format 2016-05-24T05:07:57.756Z and set it to something like 2016-05-25T00:00:00.000Z? Any assistance would be greatly appreciated. ...

How can I execute a query in Django where the values of (fielda, fieldb) must be limited to the pairs (1, 2) and (3, 4)?

Is there a way to run a query in Django that checks if pairs of fields (fielda, fieldb) are in a specific set of pairs like (1, 2) and (3, 4)? It seems like this isn't achievable using filter or Q queries. Do I need to resort to using a raw SQL query ...

Trouble arises when accessing GET form in php/Ajax

I am in the process of creating a dynamic website. At the top, I have an input form that, when submitted, should display the output from an asynchronous request to a PHP page using echo to show what was submitted. Unfortunately, it's not functioning ...

What are the steps to use the vue-text-highlight feature?

I am attempting to implement an example from the basic usage section of https://github.com/AlbertLucianto/vue-text-highlight. However, upon opening index.html in Firefox, I am only greeted with a blank page. You can find the code I am using at https://git ...

Changing the href of an image when the slide changes: Tips and tricks

Currently, I am utilizing the slick slider slideshow and facing an issue with updating the href of a logo image as the slides progress. Despite trying out two different scripts, none of them have proven to be effective. <main class="Site-content"> & ...

React's JS is having trouble accepting cookies from the express server

I've encountered an issue where sending cookies from my express server using res.cookie() is not working with the front end. Even though I include {withCredentials:true} in the get requests, the cookies are not being set in the browser's applicat ...

I'm having trouble understanding the process of setting up and utilizing bootstrap with Vue.js

After creating a new project in Vue.js with the latest version, I decided to add Bootstrap for styling my table. However, I kept encountering an error in the console that said: Failed to resolve component: b-table Despite following Bootstrap's docu ...

Transforming the output of a PHP script from an HTML table into an ion-list format tailored for the Ionic framework

Currently I am working on an application built with the Ionic framework. I have developed a PHP file to retrieve 'Users' data from my database and it is currently being displayed in an HTML table format. In the services section of the framework, ...

How to delete vertices and their properties from a BufferGeometry using Three.js

In my Three.js project, I have a large collection of point cloud forms grouped together in a single Points object for efficient rendering using BufferGeometry in WebGLRenderer. The program allows users to interactively select a form from the point cloud, w ...

Update the Vue component upon fetching new data

How can I continuously refresh the list of items when a button in a sibling component is clicked? The watch method only triggers once, but I need it to constantly refresh. This is the parent element: <template> <div class="container"& ...

Error message: "The property is not found within the specified type when using the OR operator with

Within my Angular component, I am faced with a challenge involving an Input that can be one of two types. @Input() profile: UserProfileDetails | BusinessProfileDetails; The structure of the profile template is straightforward and I want to avoid duplicati ...

Updating the content within a div following the submission of a contact form 7

I'm struggling with my contact form. I want the content of my contact form div to change after clicking submit on the form. I've been searching for a solution, but so far, no luck. Here is what I have: Form (div1) with input fields, acceptance c ...

JavaScript anchor scrolling

I am currently working on building a website with anchor navigation similar to what is used on platforms like Facebook and Google Mail. I have managed to get it partially working, but there are still some issues. For example, when I load the page with some ...

Can you guide me on implementing AWS SDK interfaces in TypeScript?

Attempting to create an SES TypeScript client using AWS definitions file downloaded from this link My approach so far: /// <reference path="../typings/aws-sdk.d.ts" /> var AWS = require('aws-sdk'); var ses:SES = new AWS.SES(); The error ...

The property for the JQuery keyboard event code is consistently null

Per information from MDN, keyboard events are supposed to have a code property that returns a string constant like "KeyA" if the A key has been pressed. However, in my JQuery keyup event handler, the code property always remains undefined: $(document).on( ...

Stop the closure of confirmation box by disabling the space key

I've been working on a website that features a table for users to interact with. Within one column of the table, there are input boxes where users can write notes. Below each input box, there is a save button to store the entered notes in a database. ...

Preserve selected option in select box after page refresh in JSP

I'm working on a jsp page that contains a simple select html element. Right now, when I select an option and click the Wyswietl button, the page refreshes, the table data is refreshed, but the selected option resets to default... How can I make it sta ...

Verify whether the external JavaScript file has already been loaded

After a successful ajax request, I am loading a script using the following code: $.getScript(base_url + 'js/js_to_be_loaded.js'); Is there a way for me to check if that specific script has already been loaded? Thank you. ...

Include a lower border on the webview that's being shown

Currently, the webview I'm working with has horizontal scrolling similar to a book layout for displaying HTML content. To achieve this effect, I am utilizing the scroll function. My inquiry revolves around implementing a bottom border on each page usi ...