What is the process for making a Vue.js widget with vue-custom-element and Vue.js3 within an HTML document?

Currently, I am in the process of learning how to develop a straightforward VueJs Widget utilizing vue-custom-element within a basic HTML page to enable its usage wherever deemed necessary.

My approach involves incorporating it as shown below:

<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bacccfdf97d9cfc9ced5d797dfd6dfd7dfd4cefa899489948a">[email protected]</a>/dist/vue-custom-element.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/document-register-element/1.4.1/document-register-element.js"></script>
<script>
  Vue.customElement('test-widget', {
    template: `<div>Hello World!</div>`
  });
</script>

Unfortunately, upon attempting to load the page, I encountered 2 issues:

  1. Uncaught TypeError: window.Vue.use is not a function at vue-custom-element.min.js:6:9328
  2. Uncaught TypeError: Vue.customElement is not a function

I suspect there may be compatibility concerns at play, but I am uncertain. Therefore, any assistance provided in resolving this matter would be greatly appreciated. Just to reiterate, my objective is to have it functional on an HTML page rather than Vue CLI, so any alternative implementation suggestions are welcomed as well.

Answer №1

According to the Description of vue-custom-element:

This package is compatible with Vue versions 0.12.x, 1.x, and 2.x.

You currently have https://cdn.jsdelivr.net/npm/vue, which points to version 3.x.

To switch to the latest 2.x version of Vue, use the following code:

<script src="https://unpkg.com/vue@2/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="691f1c0c440a1c1a1d0604440c050c040c071d295a475a"><span class="__cf_email__" data-cfprint="289736393b27303875323e02373b31383677783d363a323077db3438397"></span></a>/dist/vue-custom-element.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/document-register-element/1.4.1/document-register-element.js"></script>
<script>
  Vue.customElement('test-widget', {
    template: `<div>Hello World!</div>`
  });
</script>

<test-widget></test-widget>

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

When a radio button is clicked in Angular7 and it shares the same form control name, both radio buttons are being

Visit this StackBlitz link for more information. places = ['effil tower','new discover'] new FormGroup({place: new FormControl()}); <div *ngIf="places?.length > 0" class="col-12"> <div style=" padding-top: 1e ...

What makes the ng-file-upload Upload service so special?

Why do I need to use the Upload service with ng-file-upload in this specific way? Upload.upload({ url: '/postMyFormHere', data: { fileToUpload: model.file, someField1: model.field1, someField2: model.field2, ...

The index.html file is missing from the "out" folder when exporting with NextJs

After completing my Next.js app, I decided to use static exporting in order to host the project on my own hosting platform. Since my app is quite simple, I didn't utilize all of the features that Next.js has to offer. However, when I ran the command n ...

I am experiencing an issue with using double quotation marks in VS Code

Whenever I press the double quote symbol like this "", the cursor automatically moves to the end. While this may be natural, I would prefer the cursor to move inside the double quotes automatically when pressing them. Additionally, it's a bi ...

Can you please explain the distinction between angular.equals and _.isEqual?

Do these two options offer different levels of performance? Which one excels at conducting deep comparisons? I've encountered situations where Angular's equals function fails to detect certain differences. In addition, I've observed that th ...

Is there a way to trigger the onclick event while dragging the div?

Exploring a Div: <div id="up" onmousedown="handleMouseDown('url(/scanToUserBox/img/cpt_subfunc_005_prev_p.png)', this)" onclick="changePage('up')"> </div> Upon clicking the div, the onmousedown event is trig ...

Assigning data to a dropdown in AngularJS using two separate controllers

Currently working with angularJS, I am exploring ways to bind the value of a select element within the scope of controller A and use it as an argument for an ng-click call (specifically the getQuizByCampID() Function) in the scope of controller B. Initial ...

Send Summernote code data using Ajax to PHP which will then store it in the database

I have implemented a Summernote editor on a page where users can input content. When a user submits the page, I use jQuery to retrieve the HTML code from the editor and then send it to a PHP script for insertion into a database. The HTML retrieved before s ...

Implementing Othello Minimax Algorithm in React.js Yields Unsuccessful Results

I need assistance with a recurring issue where the AI player consistently plays the first available move it encounters. My objective was to implement an AI using the Minimax Algorithm, but I'm facing challenges in achieving the desired functionality. ...

Clicking to reveal a v-date-picker v-menu and automatically focusing on a v-text-field within it?

I implemented a date-picker component in my app following the instructions from Vuetify. To enhance usability for desktop users, I removed the readonly attribute to allow manual input. Now, desktop users can easily navigate through form fields using th ...

Utilizing PHP for XML exportation and fetching it through AJAX to integrate it into the DOM, unfortunately, the XML content remains invisible

I've encountered a strange issue with a PHP script that generates valid XML output. I'm trying to fetch this data using an Ajax XMLHttpRequest call in the browser. Although Firebug confirms that the Ajax request is successful and the XML is vali ...

"Enhancing User Experience with AngularJS by Dynamically Modifying and Refresh

I'm currently attempting to dynamically add HTML elements using JavaScript with a directive: document.getElementsByClassName("day-grid")[0].innerHTML = "<div ng-uc-day-event></div>"; or var ele = document.createElement("div"); ele.setAttr ...

Listening for events on an array of elements using jQuery

My task involves populating an array with elements using the .each() method and the $(this) selector. (function($){ var elements = new Array(); var index = 0; $("img").each(function() { if($(this).attr("attribute")){ $(thi ...

How can one ensure the preservation of array values in React?

I'm struggling to mount a dynamic 'select' component in React due to an issue I encountered. Currently, I am using a 'for' loop to make API calls, but each iteration causes me to lose the previous values stored in the state. Is t ...

The luminosity of MeshBasicMaterial in Three.js

In my current setup with threejs, I am utilizing MeshBasicMaterial for lighting effects. Each element contains a simulated point light within. I have assigned a variable named color, defined as rgb(random value, random value, random value). I am looking ...

Accessing $refs in Vue.js results in an undefined value

Encountering difficulties with the reference, ref, of a tag as it is currently returning null. Excerpts from the code are displayed below: <input-layout v-if="edit" label="Status" class="" ref="statusSubtitle"> ...

Grasping the idea of elevating state in React

I can't figure out why the setPostList([...postList, post]) is not working as expected in my code. My attempts to lift the state up have failed. What could be causing this issue? The postList array doesn't seem to be updating properly. I'v ...

The regular expression tool is unable to locate and substitute a string that includes parentheses

Seeking help in identifying and highlighting a sentence within a paragraph (found in a textarea). The current method works fine for sentences without parentheses, but struggles with replacing strings surrounded by ""mark"" tags. Is there a way ...

What could be causing my Node application to give a 404 error when making a POST request?

I'm at a loss trying to debug my app for what seems like a simple error, but I just can't locate it. Here is an overview of how my Express app is structured. My routes are set up as follows: var routes = require('./routes'); ... app.g ...

"Exploring the intricacies of routing within a Node.js application

I previously had around 100 blogs displayed on the "/" page with links for sorting by date (a-z). When clicking on these links, I am redirected to different routes - one is "/sort_by_date" and the other is "/sort_alphabetically". Unfortunately, I was unabl ...