S
S
Secret732019-01-17 21:41:53
JSON
Secret73, 2019-01-17 21:41:53

How to access data in an array?

Hello.
php file

<?
$aMenuLinks = Array(
  Array(
    "Каталог курсов",
    "index.php",
    Array(),
    Array(),
    ""
  ),

  Array(
    "Мои курсы",
    "mycourses.php",
    Array(),
    Array(),
    ""
  ),
);
echo json_encode($aMenuLinks);
?>

vue
<div id="app2">
            <div v-for="inform in info">
                {{ inform }}
            </div>
        </div>
            var app2 = new Vue ({
                el: '#app2',
                data() {
                    return {
                        info: null
                    };
                },
                mounted() {
                    axios
                        .get('test.php')
                        .then(response => (this.info = response.data));
                }
            })

Result
[ "Каталог курсов", "index.php", [], [], "" ]
[ "Мои курсы", "mycourses.php", [], [], "" ]

Question: How can I pull out a separate Link Title, and a separate link?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Somewhere Intech, 2019-01-17
@Secret73

If you change in PHP file

<?
$aMenuLinks = Array(
  Array(
    "page"=>"Каталог курсов",
    "link"=>"index.php",
    "foo" => Array(),
    "bar" => Array(),
    "dollar"=> ""
  ),

  Array(
    "page"=>"Мои курсы",
    "link"=>"mycourses.php",
    "foo"=> Array(),
    "bar" =>Array(),
    "dollar" =>""
  ),
);
echo json_encode($aMenuLinks);
?>

then you can
<div id="app2">
            <div v-for="inform in info">
                <a v-bind:href="inform.link">{{inform.page}}</a> 
            </div>
            var app2 = new Vue ({
                el: '#app2',
                data() {
                    return {
                        info: null
                    };
                },
                mounted() {
                    axios
                        .get('test.php')
                        .then(response => (this.info = response.data));
                }
            })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question