I am passing an array to a component in Vue.js but it is not passing properly. Strings pass fine. My code is below:
Vue code
<template>
<div class="panel panel-default">
<div class="panel-heading">{{c}}</div>
<div class="panel-body">
</div>
</div>
</template>
<script>
import axios from 'axios';
export default {
mounted() {
console.log('Component ready.');
},
props: ['f','c'],
data : function() {
return {
}
},
And the HTML/PHP
<div class="container">
<div class="row">
<div class="col-md-12">
<?php $a = ['Pasta', 'Chicken', 'Rice']; ?>
<credits f= $a c="One"></credits>
</div>
</div>
</div>
In this case "c" works fine and "f" doesn't.
How can I do this properly?
也许尝试使用json_encode()
对值进行编码,如下所示:
<credits f="<?= json_encode($a)?>" c="One"></credits>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.