为什么Vue js组件未在laravel刀片中显示?

时间:2019-02-14 05:16:31

标签: javascript laravel vue.js

我正在尝试修复组件中的以下错误,但仍然失败。错误如下

  

[Vue警告]:未知的自定义元素:-您是否正确注册了组件?对于递归组件,请确保提供“名称”选项。

在我的密码组件的以下脚本中,我具有以下内容:

<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>

问题在于打开页面时vue组件未加载,并且刷新后错误消失了。

在laravel刀片中,我通过以下方式使用它:

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

在app.js中

我有以下脚本

Vue.component('password-input', require('./components/PasswordInput.vue'));

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

有人可以指导我如何解决它吗?如果有人可以指导我解决这个问题,我将不胜感激。

2 个答案:

答案 0 :(得分:0)

我认为这段代码在语法上是不正确的,或者您可能省略了部分代码:

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

可能是这样的:

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

答案 1 :(得分:0)

我同意这行似乎有些奇怪;

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

您是否添加了组件标签的开头部分?即<password-input @if($errors->has('password')) ...


但是我认为您不能在Vue组件中使用可选道具,因此,如果没有错误,您将不会将任何内容传递给Vue组件。

也许尝试这样的事情:

<password-input
    :error="'{{ $errors->has('password') ? $errors->first('password') : null }}'"
></password-input>
相关问题