Original: Unknown custom element and directiveRewritten: M

In the process of learning Vue, I am attempting to create a dynamic table using Vue2 with a product selector (Select2 component), tax calculations (methods), and input formatting rules (Inputmask).

Most components are functioning correctly, but mixed sub-components and directives are not working as expected.

I have imported all components/directives in Webpack. Here is the entry JS:

import DecimalMask from './directives/inputmask/decimal-mask';
new Vue({
el: '#vue-app',
components: {
    ....
    'select2-ajax': Select2Ajax,
    'select2-simple': Select2Simple,
    'dynamic-table': DynamicTable,
},
directives: {
    'price-mask': PriceMask,
    'decimal-mask': DecimalMask,
    'date-mask': DateMask,
    ....
}
});

This is the DynamicTables component:

export default {
    props: {
        tableRows: {
            type: Array,
            default: function(){ return [{}] }
        }
    },
    data: function() {
        return {
            rows: this.tableRows
        }
    },
    computed: {
        total: function () {
            var t = 0;
            $.each(this.rows, function (i, e) {
                t += (e.price * e.qty);
            });
            return t;
        }
    },
    methods: {
        addRow: function () {
            try {
                this.rows.push({});
            } catch (e) {
                console.log(e);
            }
        },
        removeRow: function (index) {
            if(this.rows.length > 1)
                this.rows.splice(index, 1);
        }
    }
};

And here is the inline-template section:

...
<tr v-for="(row, index) in rows">
    <td>
        <select2-ajax
                inline-template
                v-model="row.product_id"
                ajax-source="{{ AURL::to('common/product-suggestion') }}">
            <select name="product[]" class="form-control">
            </select>
        </select2-ajax>
    </td>
    <td>
        <input v-decimal-mask class="form-control" name="qty[]" v-model="row.qty" number/>
    </td>
    <td>
        <input v-decimal-mask.price class="form-control text-right" name="price[]" v-model="row.price" number data-type="currency"/>
    </td>
    <td>
        <input v-decimal-mask.price class="form-control text-right" name="total[]" :value="row.qty * row.price" number readonly />
    </td>
    <td>
        <button type="button" class="btn btn-danger col-md-12" @click="removeRow(index)"><i class="fa fa-times"></i></button>
    </td>
</tr>
...

Currently encountering errors in the DynamicTables component:

  • Unknown custom element: - Have you registered the component correctly? For recursive components, ensure to provide the "name" option.

  • Failed to resolve directive: decimal-mask

The component and directive work perfectly in other instances but for some reason are not functioning when mixed within other components. They should work since they exist in the same Vue instance. Thank you!

Answer №1

Ensure you register these globally so they can be accessed throughout your application:

import DecimalMask from './directives/inputmask/decimal-mask';
Vue.directive('decimal-mask',DecimalMask);
....
import customComponent from './Components/customComponent.vue'
Vue.component('custom-component',customComponent);
...
new Vue({...})

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

Displaying a distinct component depending on a specific condition within an iteration

My latest project involves a simple Minesweeper game, and I've encountered an interesting decision-making process when it comes to rendering the cells. There are three possibilities: Unrevealed cell Revealed mine cell Revealed neutral cell To handl ...

Accessing instance variables from a chained observable function in Angular 2/Typescript

Currently, I am utilizing Angular2 along with Typescript. Let's assume that there is a dummy login component and an authentication service responsible for token authentication. In one of the map functions, I intend to set the variable authenticated as ...

Tips for integrating H4 - H6 using a text editor in DNN7

It is essential for my client to have access to at least H4. Although I can add H4 to the ApplyClass menu in the text editor, it only applies a <span class="h4"> Sample </span> tag within the paragraph itself. Unfortunately, this method does ...

Is it possible to create a popup window that remains fixed at the top edge of the screen but scrolls along with the rest of the page if

In an attempt to organize my thoughts, I am facing a challenge with a search page similar to Google. The search results trigger a popup window when hovering over an icon, located to the right of the search results. Here is what I am looking to achieve with ...

A peculiar outcome arises when running a Vue.js project folder on MacOS using the Vite development server

While working on a MacOS system, I encountered an issue when copying the entire directory of a vue.js 3 project using the command: cp -rp dir1 dir2. Subsequently, when attempting to run a development server in the copied directory (dir2) with the command: ...

Manipulating Arrays in JavaScript: Techniques for Extracting Values Buried in Nested Objects

I am working with an array of objects that contain multiple "Book" objects with dynamic keys. My goal is to filter the objects in the array to only include those that have at least one new "Book" object. For example: const arr = [ { id: '123&ap ...

Utilize the "v-on:" directive in VueJS to attach an event listener to the <router-link> component

I'm currently working on integrating a custom handler called InlineButtonClickHandler to the <router-link> component's click event. The purpose of this customization is to emit a specific appSidebarInlineButtonClick event. Despite my effor ...

JavaScript, detecting repeated characters

I need to create a script that checks an input box (password) for the occurrence of the same character appearing twice. This script should work alongside existing regex validation. I believe I will need to use a loop to check if any character appears twice ...

Utilize FileHandle throughout various versions of Node.js

Is it possible to import the FileHandle module successfully across different versions of Node.js? For example, in Node.js v14 and v16, the following code functions properly: import { FileHandle } from "fs/promises"; However, in Node.js v12, thi ...

Differentiate the iframe goal

As someone who is brand new to JavaScript, I am stepping out of my comfort zone and trying something unfamiliar in order to learn. Currently, I am coding an HTML website and have incorporated an iframe element. My goal is to display different HTMLs within ...

Ways to effectively handle child events generated programmatically in Vue.js?

There are two components - a child and a parent. The child component is renderless and does not have a tag like <app-child></app-child> for instantiation in the template. Instead, I manually instantiate the child in the parent and mount it ma ...

jQuery Ajax error 403 (unlike XMLHttpRequest)

Recently, I encountered an issue with two Ajax calls in my code. One of the calls was implemented using XMLHttpRequest and the other one using jQuery. Surprisingly, the first call completed successfully without any errors. However, the second call, which s ...

Make an AJAX request to a PHP page without having to refresh the page every time the

I am looking to utilize AJAX to call a PHP page without having to reload PHP classes each time. For example, upon the first running of AJAX, the PHP page loads and sets data. However, on subsequent runs of AJAX, I want the PHP page to retrieve the same dat ...

VUE does not support the display of Chinese characters

When trying to display Chinese characters in a VUE project, I made sure to set utf-8 in index.html https://i.sstatic.net/AJaLsyO8.jpg Unfortunately, after finishing the coding and running "npm run dev" to start the web app, https://i.sstatic.net/6ZLLIXBM. ...

Updating the ContextKey of the DynamicPopulateExtender based on the selected value from a DropDownList dynamically

I am facing an issue with my DynamicPopulateExtender control. I need it to render HTML based on the value of an asp:DropDownList. The problem lies in writing the JavaScript code that can fetch the dropdown value, assign it to the DynamicPopulate control&ap ...

Determine the number of objects in a JSON array and compile a new array containing the sum of the

I am working with a JSON array that looks like this: const arrayVal = [{ "DATE": "2020-12-1", "NAME": "JAKE", "TEAM_NO": 2, }, { "DATE": "2020-12-2"`, "NAME" ...

Generating a dynamic sitemap with Next.js

I have been working on a project where I need to create a sitemap, and I am currently using next-sitemap for generation. However, I've encountered an issue with this method, as well as other solutions I've come across, because the sitemap is only ...

Is it feasible in Angular 10 to have varying data for dynamic routes?

Take a look at the following dynamic route: export const routes: Routes = [ { path: 'template/:templateId', component: TemplateComponent, data: { pageTitle: 'TEMPLATES'} }] Can we dynamically change the pageTitle for the ...

Unable to retrieve the store's vuex state

Below is the main file path /main.js import Vue from 'vue'; import App from './App.vue'; import vuetify from './plugins/vuetify'; import router from './router'; import store from './store/index.js'; Vue.c ...

Implementing styles on the parent document through the child document

Currently, I am working on a chat widget application script and my goal is to apply styles to the parent document's body from the child document (the chat widget application). So far, I have attempted to access the parent document using the window ob ...