@adan
To pass a PHP array to Vue.js, you can follow these steps:
- Encode the PHP array into JSON using the json_encode() function. This will convert the PHP array into a JSON string.
$phpArray = ['item1', 'item2', 'item3'];
$jsonArray = json_encode($phpArray);
- Create a Vue instance and assign the JSON array to a data property.
var app = new Vue({
el: '#app',
data: {
vueArray: [],
},
mounted() {
// Assign the JSON array to the Vue data property
this.vueArray = ;
},
});
- Make sure to include the Vue.js library in your HTML.
That's it! The PHP array will be passed to Vue.js and rendered in the HTML template using v-for
.