Passing an array to a component in Vue.js 2.0

旧街凉风 提交于 2019-12-25 09:16:10

问题


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:


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

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



来源:https://stackoverflow.com/questions/41577211/passing-an-array-to-a-component-in-vue-js-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!