Passing an array to a component in Vue.js 2.0

2019-09-04 20:17发布

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?

1条回答
\"骚年 ilove
2楼-- · 2019-09-04 20:45

Maybe try to encode the value using json_encode()like this:

<credits f="<?= json_encode($a)?>" c="One"></credits>

查看更多
登录 后发表回答