php - Laravel and vue pass array to prop -
i've got multiselect component looks this:
<multi-select prp-selected="<?php old('organisations_working_at') ?>" prp-name="organisations_working_at" :prp-options="{{ json_encode($organisations) }}" prp-placeholder="kies organisatie(s)"> </multi-select>
as can see pass old('organisations_working_at')
value laravel.
my component looks (i made wrapper around multi-select):
<template> <div> <input type="hidden" v-for="select in selected" :name="prpname + '[]'" :value="select.id"> <multiselect v-model="selected" :multiple="true" :options="prpoptions" :custom-label="prpcustomlabel" :placeholder="prpplaceholder" track-by="id" selectlabel="druk op enter en voeg toe" deselectlabel="druk op enter en verwijder" open-direction="top" @select="select" @remove="remove"> </multiselect> </div> </template> <script> import multiselect 'vue-multiselect'; export default { components: { multiselect }, props: { prpselected: { type: array, default: this.selected, }, prpoptions: { type: array, default: this.options, }, prpcustomlabel: { type: function, default: (label) => label.name, }, prpplaceholder: { type: string, default: "kies items" }, prpname: { type: string, default: "items" } }, created() { this.selected = this.prpselected; }, data() { return { selected: [], options: [] } }, methods: { select(value) { this.$emit('optionadded', value.id); }, remove(value) { this.$emit('optionremoved', value.id); } } } </script>
but when vue devtools selected (when receive failed validation response laravel):
selected:""
when dd(old('organisations_working_at'));
not empty , array.
what doing wrong?
i believe need set prop like:
prpselected: { type: array, default: [] }
and return data it's:
selected: this.prpselected ? this.prpselected : []
Comments
Post a Comment