Answer the question
In order to leave comments, you need to log in
How to embed vue in a Yii2 project?
Hello, there is a project on Yii2, some pages are interactive applications. What is the best way to build a project, write an application separately and then just include the assembled js file? On some vue apps you will need to use router and store. It will also be necessary to write a chat, I also thought to write it on vue, how in this case to insert a chat on the site? how is the widget?
Answer the question
In order to leave comments, you need to log in
Are you using a webpack-based build?
In Yii2, you will need to make two layouts: one for regular pages ( view/layouts/main.php
), the second for pages with Vue ( view/layouts/vue.php
)
For dev mode, view/layouts/vue.php
you need to include JS scripts in the file that generates npm start
. To do this, open the source code of the page that webpack distributes and copy all the included <script>
. Either manually or write a parser. It seems that these scripts have static names, so it's easier here. You can copy and forget once.
For the prod mode, you need to include in the layout view/layouts/vue.php
the final compressed JS scripts that it generates npm run build
- the difficulty here is that these scripts always have unique names.
I will try to make an example on github
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question