現在、複数の「入力フィールド」コンポーネントで登録フォームを作成しようとしています。それらは現在、内部のテキストが変更されたときに、それぞれが独自に検証しますが、すべての入力フィールドをグローバルに呼び出してすべてを検証することは困難です。私は何を達成しようとしていることは以下の通りです:http://vee-validate.logaretm.com/examples#validate-formVee-Validateとvue jsを使用してサブミット時に子入力コンポーネントを検証する2
はい、これがこの質問Validate child input components on submit with Vee-Validate にsimmilerである。しかし、私はsingleInput.vue
<template lang="html">
<div :class="'col m'+col">
<div class="input-field">
<i v-if="icon" class="material-icons prefix">{{icon}}</i>
<input
v-if="area"
:type="type"
@input="onChange"
:id="id"
:required="required"
:name="id"
v-validate="'required'"
/>
<textarea
v-if="!area"
@input="onChange"
:id="id"
:required="required"
:name="id"
class="materialize-textarea"></textarea>
<label :for="id">
{{label}}
<span v-if="required" class="red-text">*</span>
</label>
<span class="red-text error">{{$store.state.errors[id]}}</span>
</div>
</div>
</template>
<script>
export default {
name:'single-input',
props: {
col:{
type: Number,
default:6
},
id:{
type: String,
required:true
},
required:{
type:Boolean,
default: true
},
label:{
type:String,
required:true
},
onChange:{
type:Function,
required:true
},
area:{
type: Boolean,
default: true
},
type:{
type: String,
default: "text"
},
icon:{
type:String
},
validation:{
type:String
}
}
}
</script>
<style lang="css">
</style>
とInfo.vue
を持ってを理解しません
<template lang="html">
<div class="row">
<single-input v-for="(info,i) in informations" :id="info.id" :label="info.label" :onChange="onChange" :area="info.area" :key="i" :required="info.required" :col="info.col" :type="info.type" :icon="info.icon"></single-input>
</div>
</template>
<script>
import SingleInput from "./SingleInput";
export default {
name: 'info',
methods:{
onChange(e){
}
},
data(){
return{
informations:[
{
label: "First Name",
id: "fname",
icon: "person"
},
{
label: "Last Name",
id: "lname",
required:false,
icon: "person"
},
{
label: "Email",
id: "email",
type:"email",
icon:'email'
},
{
label: "Telephone",
id: "phone",
type:"text",
icon:'phone'
},
{
label: "Department",
id: "depa",
type:"text",
icon:'domain'
},
{
label: "Organization",
id: "org",
type:"text",
icon:'account_balance'
},
{
label: "Address",
id: "address",
icon:'directions',
area: false,
col:12
},
{
label: "City",
id: "city",
type:"text",
icon:'place'
},
{
label: "Post code",
id: "post",
type:"text",
icon:'pin_drop'
}
]
}
},
components:{
SingleInput
}
}
</script>
<style lang="css">
</style>
私は全力を尽くしていますが、info.vueのエラーにアクセスすることはできません
お手数をおかけしますようお願い申し上げます。
これは良いことですが、バリデーターをトリガーしますが、catch()のロジックは正しくはありません(キャッチされているものは何もないようです)。しかし、その問題を解決するのは簡単で、この問題に対するすっきりした解決策です。 – philw