Steps for importing Vue components from the browser using a CDN

Trying to incorporate a Vue.js component (@chenfengyuan/vue-qrcode) using UNPKG as CDN has been my focus.

The current setup is as follows:

<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5422213114667a627a64">[email protected]</a>"></script>
<script src="https://unpkg.com/@chenfengyuan/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="166063733b676475797273562738263827">[email protected]</a>/dist/vue-qrcode.min.js"></script>
<script>Vue.component(VueQrcode.name, VueQrcode);</script>

<script type="module" src="/client.js"></script>


Within my client.js file, the Vue instance is defined as:

new Vue({
  el: "#app",
  data: {
    msg: "Vue js Hello World - Your First Vue.js App"
  }
});

The desired setup would be something like this:

<script type="module" src="/client.js"></script>

Subsequently, the content of client.js would appear along these lines:

import Vue from 'https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7701021237455941594647">[email protected]</a>/dist/vue.esm.browser.js'

import VueQrcode from 'https://unpkg.com/@chenfengyuan/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="413734246c3033222e252401706f716f70">[email protected]</a>/dist/vue-qrcode.min.js'

Vue.component(VueQrcode.name, VueQrcode);
new Vue({
  el: "#app",
  data: {
    msg: "Vue js Hello World - Your First Vue.js App"
  }
});

The Vue template (embedded in HTML) appears as such:

<div id="app">
      <h1>{{ msg }}</h1>
      <qrcode value="https://queue-r.glitch.me" :options="{ width: 200 }"></qrcode>
</div>


Regrettably, this approach fails to work as intended. The console simply indicates that the custom tag is not being recognized. My goal with this method is to achieve complete separation between my Vue code and the HTML structure.

Can anyone offer guidance on why it's not functioning as expected? Any thoughts?

Answer №1

Your provided example seems to be working without any issues. Please see a demo of the code below:

new Vue({
  el: "#app",
  data: {
    msg: "Hello from Vue.js - Your First Vue App"
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://unpkg.com/@chenfengyuan/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f7818292da868594989392b7c6d9c7d9c6">[email protected]</a>/dist/vue-qrcode.min.js"></script>
<script>Vue.component(VueQrcode.name, VueQrcode);</script>

<div id="app">
      <h1>{{ msg }}</h1>
      <qrcode value="https://queue-r.glitch.me" :options="{ width: 200 }"></qrcode>
</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

Obtain a Calculated Result from a Loop in Vue

I am currently working on a project where I need to check which checkboxes are ticked in different categories so that I can display the total number of checked items next to each category name. I have come up with a code that loops through the selected ite ...

Modifying `msg.sender` in Solidity and Ether.js

I have a Smart Contract written in Solidity. Within this contract, there is a function called makeMarketItem. function makeMarketItem( address nftContract, uint256 tokenId, uint256 price ) public payable nonReentrant { IERC721(nftContract). ...

The use of "Undefined in res.redirect" is a common issue that may arise when working with a combination of libraries such as

Encountering an issue while trying to redirect the user to a signature route with the file name as a URL argument, and receiving undefined... Example of a file as a URL argument after upload: http://localhost:3000/undefined?arquivo-assinado=82a35943-5796 ...

Using AJAX to dynamically update content via HTTP requests

Why do I keep seeing "loading..." instead of the content from data.php? xmlhttp = new XMLHttpRequest(); function fetchData () { xmlhttp.onreadystatechange = function () { if(xmlhttp.readyState = 4 && xmlhttp.status == 20 ...

$emit functionality within a promise

I am facing an issue with event orders in my application. I have a method for fetching data and another one to open a modal with that data, but the problem is that the modal is rendered before getting the data, resulting in the previous result briefly appe ...

Discover a specific element within an array variable

Trying to access a variable from an array but receiving an 'undefined' value, I used console.log for testing purposes. I am inspired by others using this approach in their projects and want to implement it to streamline my projects. The code is s ...

A method for iterating through JSON data and assigning a specific key name to a variable based on a corresponding string

A JSON object is returned from the event.body in a function like this: exports.handler = async (event, context, callback) => { {"name":"Anders","package":"Silver","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fd9 ...

Typescript - utilizing forward and useref functionality

I am working with two components: const ComponentOne = () => { const a = React.useRef<WhatTypeGoesHere>(null); // ^^^^^^^^^^ encountering error - ComponentTwo is treated as value instead of type here const fn = () => { ...

Guide on transferring an array with a specific key to a function parameter (Dealing with multidimensional arrays)

While this question may seem a bit random, it actually does make sense - at least to me. Let's consider a multi-dimensional array named temporaryFrequency. I want to create a function that takes one argument - frequencyArray[number]. Let's have a ...

Tips for adding a border to a 3D pie chart in Highcharts

I created a 3D pie chart using the Highchart plugin and wanted to add borders to each portion. I tried adding the following code: borderWidth: 4, borderColor: "red" within the plotOptions: pie: section. However, I noticed that the portions were getting b ...

What is the best way to combine relative paths or create distinct identifiers for SVG files located within multiple layers of folders

I have a collection of icons exported from "Figma" organized in folders, and I'm using grunt-svgstore to create a sprite sheet. However, the result contains duplicated IDs even after trying 'allowDuplicateItems: false' and 'setUniqueIds ...

Guide to smoothly scroll to a specific Label using GSAP's scrollTrigger and scrubbing within a Timeline

Currently facing an issue with a scrollTrigger Timeline where I need a button to scroll to a specific position. I attempted using seek but it did not work, and even the ScrollTo plugin lacks support for this functionality. The Timeline created using gsap ...

Unable to display the popup modal dialog on my Rails application

I currently have two models, Post and Comment. A Post has many Comments and a Comment belongs to a Post. Everything is functioning properly with the creation of posts and comments for those posts. Now, I have a new requirement where when clicking on "crea ...

Establish a variable in XSL to define the tabIndex

My XSL code has been designed to read an XML file and generate input elements of type text for each child node. The XML file structure is as follows: For node c, two input boxes are created in the format: Label(com 1) :input box--------------------- Label ...

managing nested JSON arrays in JavaScript

I have a straightforward task with handling a simple array that is divided into two parts: a group of vid_ids and a single element named page. Initially, I was iterating through the vid_id array using a for loop. However, upon adding the page element, I en ...

"How to Save Data to an XML File on an Apache Server using jQuery without the need for Server-Side Scripting

I've managed to retrieve XML data from a file on the server side without using any server-side scripts like PHP. Now, I want to make some minor modifications to this XML data and write it back to the file on the server side without utilizing server-si ...

Tips for assigning an ID to a span element within a for loop

I am facing a challenge where I need to assign IDs to span tags that do not have the id attribute. These IDs need to be assigned sequentially by incrementing through a for loop and passing my geneologicalSequenceNumber into each span tag. Can you guide me ...

Adjustable height within embedded object tag

I've been struggling to adjust the height of the content on my site automatically. I have attempted using iframes as well, but nothing seems to work despite trying numerous code examples from various sources including CSS and JS scripts. Any help wou ...

Form validation errors were detected

Currently, I am working with a formgroup that contains input fields with validations set up in the following manner: <mat-form-field class="mat-width-98" appearance="outline"> <mat-label>Profession Oc ...

"Ways to retrieve an array of dates within a specified range of date and time

I am working with date fields in my project { tripScheduleStartDate: '2018-12-05T18:30:00.000Z', tripScheduleEndDate: '2018-12-07T18:30:00.000Z', } Is there a way to generate a datetime array from the start date to the end date, lik ...