T
T
thorii2017-08-21 00:33:24
PHP
thorii, 2017-08-21 00:33:24

How to connect Vue.js with php?

How to pass data to Vue templates from php? The view component is connected to the page via src in the script. How do you substitute values ​​into a vue component from php for example?

<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <title>Feed</title>
</head>
<body>

<div id="app">
    <feed></feed>
</div>

<script src="/bundle.js"></script>

</body>
</html>

All the main template code is described in bundle.js. The page itself is run through the php engine for value substitution through a template engine (It was in the days without Vue, and I don’t really want to remake data substitutions into templates from the php server). I don’t really want to open bundle.js and insert the code into the page directly (naturally, this will be substitution through <?=$var?>).
Or is it better to connect the front to the backend through ajax requests to the api?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander Kramov, 2017-08-21
@thorii

> Or is it better to connect front to backend via ajax requests to api?
This.

G
Grigory Vasilkov, 2017-08-21
@gzhegow

Use this option:
from php
sometimes you can put some base64 in the form of a tag in html, so that later you can recognize it from javascript. Well, there are different ways.

A
ajaxtelamonid, 2017-08-22
@ajaxtelamonid

In php, a page template is generated along with a script block, where json is assigned to a variable, for example, windows.init_data. In a js application, data from window.init_data is passed to the store or to the state of the main component.

F
Fwwll, 2018-12-05
@adrontek

in HTML
in JS
Probably not the best solution, but there are enough pluses

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question