简体   繁体   中英

Pass data from laravel to a component in blade view

I created a PasswordFields.vue file.

<template>
<div>
    <el-form-item label="Mot de passe"
                prop="password"
                :error="this.registerForm.errors.get('password')"
                required
                :rules="[{ 'min': 6, message: 'Le mot de passe doit faire au moins 6 caractères', trigger: ['blur', 'change'] }]">
        <el-input type="password" name="password" id="password" v-model="this.registerForm.password">
        </el-input>
    </el-form-item>

    <!-- confirm password -->
    <el-form-item label="Confirmation du mot de passe"
                prop="password_confirmation"
                :error="this.registerForm.errors.get('password_confirmation')"
                required
                :rules="[{ 'min': 6, message: 'Le mot de passe doit faire au moins 6 caractères', trigger: ['blur', 'change'] }]">
        <el-input type="password" name="password_confirmation" id="password_confirmation" v-model="this.registerForm.password_confirmation">
        </el-input>
    </el-form-item>
</div>
</template>

Whenever I call my component in my Blade view, like this:

<password-fields></password-fields>

I have an error that says the property or method method is not defined on the instance but referenced during render .

I tried this, but it still does not work

<password-fields registerForm="registerForm"></password-fields>

Can you help me ? How to pass the value to my component? thank you very much

EDIT (the end of my component)

<script>
export default {
  data() {
  var validatePass = (rule, value, callback) => {
    if (value === '') {
      callback(new Error('Please input the password'));
    } else {
      if (this.registerForm.password_confirmation !== '') {
        this.$refs.registerForm.validateField('password_confirmation');
      }
      callback();
    }
  };
  var validatePass2 = (rule, value, callback) => {
    if (value === '') {
      callback(new Error('Please input the password again'));
    } else if (value !== this.registerForm.password) {
      callback(new Error('Two inputs don\'t match!'));
    } else {
      callback();
    }
  };
  return {
    rulesPass: {
      pass: [
        { validator: validatePass, trigger: 'blur' }
      ],
      checkPass: [
        { validator: validatePass2, trigger: 'blur' }
      ]
    }
  }
    }
}

  1. never use this in the template
  2. declare props in component

Example Component:

<template>
<div>
    <el-form-item label="Mot de passe"
                prop="password"
                :error="registerForm.errors.get('password')"
                required
                :rules="[{ 'min': 6, message: 'Le mot de passe doit faire au moins 6 caractères', trigger: ['blur', 'change'] }]">
        <el-input type="password" name="password" id="password" v-model="registerForm.password">
        </el-input>
    </el-form-item>

    <!-- confirm password -->
    <el-form-item label="Confirmation du mot de passe"
                prop="password_confirmation"
                :error="registerForm.errors.get('password_confirmation')"
                required
                :rules="[{ 'min': 6, message: 'Le mot de passe doit faire au moins 6 caractères', trigger: ['blur', 'change'] }]">
        <el-input type="password" name="password_confirmation" id="password_confirmation" v-model="registerForm.password_confirmation">
        </el-input>
    </el-form-item>
</div>
</template>

<script>
export default {
  data() {
  var validatePass = (rule, value, callback) => {
    if (value === '') {
      callback(new Error('Please input the password'));
    } else {
      if (this.registerForm.password_confirmation !== '') {
        this.$refs.registerForm.validateField('password_confirmation');
      }
      callback();
    }
  };
  var validatePass2 = (rule, value, callback) => {
    if (value === '') {
      callback(new Error('Please input the password again'));
    } else if (value !== this.registerForm.password) {
      callback(new Error('Two inputs don\'t match!'));
    } else {
      callback();
    }
  };
  return {
    rulesPass: {
      pass: [
        { validator: validatePass, trigger: 'blur' }
      ],
      checkPass: [
        { validator: validatePass2, trigger: 'blur' }
      ]
    }
  }
    }
}
  props: ['registerForm'],
}
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM