[Vuejs]-Vue + php, how send array to props?

1👍

You don’t understand the difference between frontend and backend part. Your front with some vue components have no knowledge if there are any variables in php.

Vue(and any js stuff) needs the data passed to view as normal js variables: using rendering them to view as text, sending them via ajax requests…

If you want to loop through $vegetables array you have to render this array to html as Burdy posted.

2👍

Just like this:

<?php
    $vegetables = ['apple', 'strawberry', 'banana'];
?>

<script>
var arr = "<?php echo implode(",", $vegetables); ?>".split(",");
console.log(arr); //["apple", "strawberry", "banana"]
Vue.component('#app7', {
    props: arr,
    template: '<li>{{ item.text }}</li>'
})

</script>

Leave a comment