F
F
First Name2018-04-02 19:25:12
Yii
First Name, 2018-04-02 19:25:12

How to properly write data to vue.js?

Hello.
The backend is Yii 2, the front is Vue.js
ON yii 2 I pass some data to the render

return $this->controller->render(
            'catalog/index',
            [
                'products' => Json::encode($this->query)
            ]
        )

In the template, I insert them into a hidden div and, using jquery, I take them from the div and write them to the properties of the Vue object
<div class="hidden" id="products"><?= $products; ?></div>

this.products = JSON.parse($('#products').text());
How to transfer them correctly?
I know it's just awful to do this, so I'm asking for advice.
Thanks for the replies :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-04-02
@webinar

Definitely json. At what I would send ajax and receive it. But you can also generate a variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question