What causes the structure of code to vary significantly across different CDNs in VueJS?

I am really struggling to understand Vue's structure. I initially learned from a video tutorial on the freeCodeCamp YouTube channel.

Later, I decided to delve deeper by reading a book called

Getting to Know Vue.js: Learn to Build Single Page Applications in Vue from Scratch

by Brett Nelson.

The issue I encountered was that while the tutorial on YouTube used unpkg, the book recommended using jsdelivr. When I tried to run the same code with both methods, it only worked with one and not the other.

I'm feeling lost because the tutorials from these two different sources are so vastly different.

This is the code I used for unpkg:

<!DOCTYPE html>
<html>
  <head>
    <title>Vue 3</title>
  </head>
  <body>
    <div id="app">
      {{ propertyName }}
    </div>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  <script>
    let app=Vue.createApp({
      data: function(){
        return {
          propertyName: 'Hello from Getting to Know Vue.js!'
        }
      }
    })
    app.mount('#app')
  </script>
  </body>
</html>

And this is the code I used for jsdelivr (it works but doesn't work with the previous script):

<!DOCTYPE html>
<html>
  <head>
    <title>Vue 3</title>
  </head>
  <body>
    <div id="app">
      {{ propertyName }}
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    let app = new Vue({
      el: '#app',
      data: {
        propertyName: 'Hello from Getting to Know Vue.js!'
      }
    });
  </script>
  </body>
</html>

Answer №1

While the codes may appear different at first, they are actually performing the same function in the end. It's just a subtle change in syntax that can be confusing at times.

It's worth noting that the jsdelivr CDN utilizes Vue2, whereas the unpkg uses Vue3, resulting in minor discrepancies when adding plugins to the DOM.

If you're looking for a recommendation, I suggest using the SFC style with a build tool like Vite: https://vuejs.org/api/sfc-spec.html#sfc-syntax-specification!

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

Is it possible to retrieve a variable from a geojson file using Vue 3 and Vite?

For my Vue 3 project, I am trying to import a variable from a geojson file. However, when I use import line from '@static/line.geojson', my page goes blank and it seems like Vue stops working. If I use import line from '@static/line.json&ap ...

Retrieving Codeigniter content at regular intervals of X seconds

Currently working on a voting app using the Codeigniter framework, I am looking to incorporate a new feature on the homepage. My goal is to update the homepage with the latest data every X seconds by retrieving item votes along with their IDs through a pre ...

Issue with scrollTop not functioning when using onclick on an <a> tag within a div

After various attempts and research online, I am still experiencing erratic scrolling behavior with the scrollTop function. My goal is to scroll within a specific div when clicking on links. The content of my div: <div id="test" style="height:400px; o ...

What is the Javascript equivalent to "new Audio()" but for video files?

When working in Javascript, accessing the HTML-5 audio object can be done like so: var audio = new Audio('nameOfFile.mp3'); However, it seems that using a similar syntax for the video element does not work (at least on Chrome). var video = new ...

Encountering an 'undefined' error while attempting to showcase predefined JSON data on an HTML webpage

As I try to display the predefined JSON data from https://www.reddit.com/r/science.json on an HTML page, I keep encountering the message "undefined." Below is a snippet of my HTML code: $.getJSON('https://www.reddit.com/r/science.json', funct ...

Update CSS transparency using PHP

My project involves a heart icon that changes appearance when hovered over, fading into a full heart instead of just an outline. If the user has already liked the heart, it should display as solid pink by default. I planned on checking if the user had like ...

Deleting a product category along with all its products: Understanding the basics of CRUD操作

I am looking for a way to delete a product category along with all the products within it. The Product model has a reference to the category as an object. Is there a straightforward method or a commonly used technique for this? I attempted to use removeAl ...

"Trouble with making jQuery AJAX calls on Internet Explorer versions 8 and 9

I've been searching for the answer to this problem without any luck. I have a page with jquery ajax calls to an API service. It works well in Chrome, Safari, Firefox, and IE 10, but fails in IE 9 and 8. Here is the code: $.ajax({ ...

Tips for showing icon-based message boxes in ASP.NET using C#

Is there a way to show a message box with different icons (like Warnings/errors/Information) in ASP.NET3.5 using C#? I tried the following code, but it didn't work as expected. ClientScript.RegisterStartupScript(this.GetType(), "Message", "alert(&ap ...

Navigating Assets within NodeJS Module

I'm facing a challenge with my NodeJS module that is designed to translate XML to HTML using an XSL file. The issue arises when I try to package the XSL file along with the rest of the module. Currently, the XSL file is located inside the source fold ...

Guide on configuring Angular validation to trigger on blur events and form submission

Validation in Angular is currently set to update on model change, but this method can be unfriendly for user interface as it displays errors upon keyup. An optimal solution would involve displaying error messages on blur and also on form submission. After ...

Retrieve information from a mysql database based on selected date using the ajax method

To retrieve data from a MySQL database based on the chosen date_time, I need to ensure that the content is seamlessly displayed without any page refresh. After successfully extracting the date_time from the database and showing it on the webpage, my focus ...

What is the proper way to initialize MongoDB and Express?

I have a unique app that utilizes express and interacts with mongodb. Here is how I typically kickstart my app: 1. Launch Mongodb mongod --dbpath data --config mongo.conf" 2. Initiate Express node server.js My pondering is, can these processes be comb ...

I am looking to insert the indexes of an array into a table data cell (<td>), with the select options being the array's indexes

I'm looking for a way to add the indexes of an array as options in a select field. However, the code provided below is not working as expected. <?php $str4 = "select * from fee_names where status = '1' "; $res4 = mysql_quer ...

Tips for using JavaScript to set images from Flickr API as img src

I've been attempting to populate a table with images fetched from flickr. The array I'm using consists of urls like: ["https://www.flickr.com/photos/113081696@N07/24695273486", "https://www.flickr.com/photos/113081696@N07/24565358002", "https:// ...

Sort columns using drag and drop feature in jQuery and AngularJS

Utilizing the drag and drop feature of jquery dragtable.js is causing compatibility issues with AngularJs, hindering table sorting functionality. The goal is to enable column sorting by clicking on the th label and allow for column rearrangement. Currentl ...

Imitate a HTTP request

Currently, I am working on developing a front-end application using Angular (although not crucial to this question). I have a service set up that currently supplies hard-coded JSON data. import { Injectable } from '@angular/core'; import { Obser ...

What is the best way to use the Object3D.lookAt() function to align an ExtrudeGeometry face with an object?

I'm trying to create a 3D Polygon that can face another Object, but I'm struggling to figure out how to do it. I was thinking of using ExtrudeGeometry, but I'm not sure how to apply the Object3D.lookat() function to it. Any suggestions would ...

Vue.js fails to show Font awesome icon

Currently, I am attempting to incorporate a font-awesome arrow icon using my CSS code as seen below: <style> .negative { color: red; } .positive { color: green; } .negative::after { content: "\f106"; } </style> Despite ...

Imagine a scenario where your json_encode function returns API data that is already in JSON format. What would

It has been a while since I last worked with JSON/PHP/AJAX, and now I am struggling to access the returned data. The AJAX function calls a PHP script that makes an API call returning JSON in $data. The JSON is then decoded using $newJSON = json_decode($da ...