1

I am trying to fix the following error from a component, but it's still failing. The error is the following:

[Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.

In my password component, following script, I have the following:

<template>
    <div class="form-group form-material floating" data-plugin="formMaterial">
        <input id="password" type="password" class="form-control" name='password'>
        <label class="floating-label">Create password</label>

        <span class="password-info"><i class="fa fa-info-circle"></i></span>
        <div class="password-rules">minimum 6 characters</div>

        <span v-if="this.error != null" :class="['invalid-feedback', {'inline': this.error != null}]">
             <strong>{{ error }}</strong>
        </span>
    </div>

</template>

<script>
    import Password from 'password-strength-meter'

    export default{
        props: ['error'],

        mounted: function(){
            const $password = $('#password', this.$el);

            $password.password({
                showText: false,
                animate: true,
            });
        }
    }
</script>

<style lang="scss">
    @import '~password-strength-meter/dist/password.min.css';

</style>

The problem is that the vue component is not loading when the page opens, and the error disappears on refresh.

In laravel blade, I am using it in the following way:

<password-input @if($errors->has('password')) :error="'{{$errors->first('password')}}'" @endif></password-input>

In the app.js

I have following script

new Vue({
    el: '#app'
});

Can someone guide me on how I fix it? I would appreciate if someone could guide me about this issue. I have seen this question but it does not resolved my problem.

Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
Imran Abbas
  • 755
  • 1
  • 7
  • 24
  • It seem like your component doesn't have the name attribute: name: "password-input", after or before your props – Lamonde Feb 13 '19 at 14:44
  • Is that assuming you have imported this password-input component from the parent component? – Yom T. Feb 13 '19 at 14:49
  • @jom I don't get your point, can you kindly explain it please. Sorry for that – Imran Abbas Feb 13 '19 at 14:50
  • Possible duplicate of ["Unknown custom element" warning inside a component tag, but not outside of it](https://stackoverflow.com/questions/46173821/unknown-custom-element-warning-inside-a-component-tag-but-not-outside-of-it) – Yom T. Feb 13 '19 at 15:15
  • @thanksd can you look this question – Imran Abbas Feb 13 '19 at 15:17
  • @ImranAbbas It doesn't look like you are importing the password component in `app.js`. Please do so and register it using the solution by jtlad below. – Yom T. Feb 13 '19 at 15:24
  • @jom But I think I am already registering it by following `Vue.component('password-input', require('./components/PasswordInput.vue'));` – Imran Abbas Feb 13 '19 at 15:25
  • @ImranAbbas OK, but you didn't mention that part anywhere in your question, so we would never know. Anyway, you are registering it globally with `require`, so try `Vue.component('password-input', require('./components/PasswordInput.vue').default)` instead, or just do ES6 import. – Yom T. Feb 13 '19 at 15:30
  • @jom sure thanks I am trying – Imran Abbas Feb 13 '19 at 15:31

2 Answers2

1

Was the component registered, usually when you create your Vue instance in app.js file.

const app = new Vue({
    el: '#app',
    components: { ExampleComponent } // Note!!!
});

You can find more information here: https://laracasts.com/discuss/channels/vue/little-help-with-laravel-and-vue-components-registration

jtlad
  • 41
  • 3
0

Hey did you ever get to the bottom of this? I have been struggling all day with the same thing. The intermittent part has been killing my productivity lol. Anyway. Like you I was using ="this.myVar" in the <template> section instead of ="myVar" and when I changed that the issue hasn't been occurring since.

sl1der
  • 136
  • 1
  • 5