How to pass an array as a prop?

Published 2 months ago by phpMick

Is this correct?:

<agreements-selector 
                                           :selected-agreements='{{ json_encode($groupingRule->agreement_ids)}}'>


I'm sure I have done this before and didn't have to use json_encode?

agreement_ids is cast to an array in the model.

Thanks,

Mick

Best Answer (As Selected By phpMick)
phpMick
MaverickChan

use double quote , and you dont really need json_encode at all

phpMick

nope:

htmlspecialchars() expects parameter 1 to be string, array given
AndreuXvz

Hi try this.

On blade .

<agreements-selector   :selected-agreements='agreementIds'></agreements-selector>

var  agreement_ids = '{{ json_encode($groupingRule->agreement_ids)}}';

On ur script.js

const vm = new Vue({ 
    data: {
        agreementIds : '' 
    }
    created () {
        this.setAgreementIds()
    }
    methods : {
        setAgreementsIds () {
             this.agreementIds = agreement_ids;
        }
    }

});

phpMick

Please sign in or create an account to participate in this conversation.