In order to use Vue3 with Vite, it is necessary to use kebab case tags for custom components, whereas Vue3 CLI allows the

I am working on a project using Vue3 with Vite (on Laravel) that has a Wiki.vue page which loads a "MyContent.vue" component.

//On MyContent.vue:
<template>
    <div>content component</div>
</template>

<script>
export default {
    name: "MyContent",
};
</script>
//On Wiki.vue:
<template>
    <MyContent />
</template>

<script>
import MyContent from "./wiki/components/MyContent.vue";
export default {
    components: { MyContent },
};
</script>
//On vite.config.js
import { defineConfig } from "vite";
import laravel from "laravel-vite-plugin";
import vue from "@vitejs/plugin-vue";

export default defineConfig({
    plugins: [
        vue({
            template: {
                compilerOptions: {
                    isCustomElement: (tag) => ["MyContent"].includes(tag),
                },
            },
        }),
        laravel(["resources/css/app.css", "resources/js/app.js"]),
    ],
});

In Wiki.vue, if I don't change the tag from MyContent to my-content, the component won't load at all. I experimented by starting a new Vue3 CLI project and found that the HelloWorld tag can remain in Pascal case and load properly. This made me wonder what the difference could be. Thanks in advance!

Answer №1

An option in the compiler has been set to recognize elements with the name "MyContent" as custom elements, preventing them from being treated as Vue components:

// vite.config.js
export default defineConfig({
    plugins: [
        vue({
            template: {
                compilerOptions: {                👇
                    isCustomElement: (tag) => ["MyContent"].includes(tag),
                },
            },
        }),
    ],
});

The template in Wiki.vue tries to use a Vue component named "MyContent", but it's not recognized due to the configuration above. However, HelloWorld.vue is not affected because the configuration targets only "MyContent".

Solution

To fix this issue, you can either remove the isCustomElement configuration or rename MyContent.vue. Since you are not using custom elements, removing the configuration seems like the best solution.

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

Combining object IDs with identical values to create a new array in JavaScript

i have an array of objects that are a join between the transaction, product, and user tables. I want to merge IDs with the same value so that it can display two different sets of data in one object. Here's my data let test = [ { Transac ...

Content will not render when JavaScript generates SVGs

As I delve into the world of JavaScript and SVG to create interactive graphics for a website, I've run into a puzzling issue with programmatically generated SVG paths not being drawn. Below is a sample code that highlights this problem: <!DOCTYPE ...

Changing the color of an input field in Vue when the delete button is clicked

I have recently started working with Vue.js and I am attempting to change the color of an input field when the user clicks on the trash-fill button. Currently, when I enter a character in the input field, it changes the color to green. Is there a way to c ...

Evaluating Vue performance with an extensive collection of objects

I'm faced with a challenge involving a lengthy list of 460 items stored in "harvesters". Below is my Vue code snippet for filtering this list: computed: { searchHarvesters() { var vm = this; let searchTerm =this.searchInHarvesters.toL ...

Collaboratively utilizing resources among various NPM Workspaces

Currently, I am working on a React project using NPM Workspaces. I have created an 'assets' workspace within this project to store all images and assets that need to be accessed by other workspaces. The directory structure of the project is as fo ...

State management using Vuex: dynamically updating values in components based on their indices and sharing the updated values with other components

I've hit a roadblock and I need your assistance. I've been struggling for the past few days with mutations and actions in Vuex, but the solutions I've found online don't quite fit my specific case. Here's the situation: Setup: - T ...

Issue with VueJS where the data list cannot be accessed from one template in another template

I'm facing an issue with my setup where there is a crash occurring on the v-for construct of the table-component. The error message displayed is: "Property or method "tablesList" is not defined on the instance but referenced during render". Strangely, ...

Revamp HTML <font size=1-7> with the use of CSS or JavaScript

I've been developing a prototype application that incorporates a plugin utilizing the deprecated HTML feature. Can I set custom pixel sizes for each font size ranging from 1 to 7? Currently, I'm contemplating using CSS zoom/scale properties, bu ...

Display a JavaScript dialogue box containing a PHP variable

Is there a way to display the correct JavaScript box when using a While loop in PHP? Here is the code snippet: while($result= mysql_fetch_array($data)){ <tr class="<?php echo $style;?>"> <td><?php echo $result['commis ...

What is the best way to choose the current Div's ID, as well as its Width and Height properties?

Within this section, there are four div elements with varying widths, heights, and colors that appear and disappear when their respective buttons are clicked. I am adding an "activeDiv" class to the visible div in order to easily select it using that class ...

Executing a function with a click, then undoing it with a second click

My goal is to trigger an animation that involves text sliding off the screen only when the burger icon is clicked, rather than loading immediately upon refreshing the page. The desired behavior includes activating the function on the initial click and then ...

What is the best method for retrieving data through an ajax call in my modular JavaScript setup?

Working with a basic modular JavaScript structure, my goal is to request a random quote from an API and display it on an HTML page using Mustache.js. I previously achieved this without the modular approach, but now I'm attempting it in a more structur ...

What are the steps to incorporate metrics middleware for Socket IO notifications, specifically monitoring both emitted events and listener activity?

I am currently working on a project that involves tracking all socket.io notification transactions initiated by the server, resembling an API request/response counter to validate subscription validation. Our team is utilizing an express middleware to moni ...

Extract the ID from the array, save it, and then delete it from the local storage

I am currently developing a mobile application using Angular, JavaScript, Ionic, and Cordova. Within one of my functions, I make use of an array called existingEntries, which is stored as a variable. categories: Array [276] [0...99] 0: Object id ...

Possible Inconsistencies with the LookAt Feature in Three.js

Attempting to use the lookAt function to make zombies move towards the character has been a challenge. The problem lies in the fact that they are not turning correctly but at odd angles. Here is the code snippet I tried: var pos = new THREE.Vector3(self ...

Troubleshooting an issue with importing a Component in ReactJS using material-ui

Using the material-ui library, I attempted to create a Table following the code provided in the Custom Table Pagination Action example. However, I encountered the following error: Error Encountered: Warning: React.createElement: type is invalid -- expect ...

I'm interested in knowing how to switch between two functions using Angular

I have developed a grocery list application where each row contains the name of a food item. The layout includes a left column for items that are not needed and a right column for items that are needed. Currently, I am able to change the state by clicking ...

"An error occurred: Attempting to access properties of an undefined object (specifically 'foundTicket'). While the getTickets() function, which fetches data from MongoDB using Mongoose, is working fine, the getTicketById()

I recently started working with next.js and I'm following a project tutorial by a YouTuber. Here is the link to my code: https://github.com/Fanguiee/ticketing-app/tree/edit-existing-item or you can also read below. Thank you in advance :) Screenshot: ...

Using the excel.js module in conjunction with node.js to create distinct columns within a header row

I am facing an issue with Excel.js while trying to add a header row to a CSV file. It seems that all the columns in the row are getting merged into one cell instead of staying separate. Does anyone know how to properly separate the columns? https://i.sst ...

The curious case of unusual behavior in jQuery's livequery() method

When attempting to use the jQuery plugin "livequery" to highlight certain words within dynamically generated search results, the highlighting does not appear to work! Strangely, adding an alert() function before executing the code causes the highlighting ...