Skip to content

Commit 371b35e

Browse files
committed
Updating documentation for newly merged recipes
1 parent 4d288e7 commit 371b35e

File tree

1 file changed

+19
-44
lines changed

1 file changed

+19
-44
lines changed

doc/index.rst

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,11 @@ Then install the bundle using Composer and Symfony Flex:
2525
2626
$ composer require symfony/ux-vue
2727
28-
Next, in ``webpack.config.js``, enable Vue.js support:
28+
The Flex recipe will automatically set things up for you, like adding
29+
``.enableVueLoader()`` to your ``webpack.config.js`` file and adding code
30+
to load your Vue components inside ``assets/app.js``.
2931

30-
.. code-block:: javascript
31-
32-
// webpack.config.js
33-
// ...
34-
35-
Encore
36-
// ...
37-
.enableVueLoader()
38-
;
39-
40-
Install a package to help Vue:
32+
Next, install a package to help Vue:
4133

4234
.. code-block:: terminal
4335
@@ -48,48 +40,31 @@ Install a package to help Vue:
4840
$ yarn add vue-loader --dev --force
4941
$ yarn watch
5042
51-
Finally, to load your Vue components, add the following lines to ``assets/app.js``:
43+
That's it! Any files inside ``assets/vue/controllers/`` can now be rendered as
44+
Vue components.
45+
46+
Usage
47+
-----
48+
49+
The Flex recipe will have already added the ``registerVueControllerComponents()``
50+
code to your ``assets/app.js`` file:
5251

5352
.. code-block:: javascript
5453
5554
// assets/app.js
5655
import { registerVueControllerComponents } from '@symfony/ux-vue';
5756
58-
// Registers Vue.js controller components to allow loading them from Twig
59-
//
60-
// Vue.js controller components are components that are meant to be rendered
61-
// from Twig. These component can then rely on other components that won't be
62-
// called directly from Twig.
63-
//
64-
// By putting only controller components in `vue/controllers`, you ensure that
65-
// internal components won't be automatically included in your JS built file if
66-
// they are not necessary.
67-
registerVueControllerComponents(require.context('./vue/controllers', true, /\.vue$/));
68-
69-
// If you prefer to lazy-load your Vue.js controller components, in order to keep the JavaScript bundle the smallest as possible,
70-
// and improve performance, you can use the following line instead:
71-
//registerVueControllerComponents(require.context('./vue/controllers', true, /\.vue$/, 'lazy'));
72-
73-
That's it! Create an ``assets/vue/controllers/`` directory and start creating your
74-
Vue components.
75-
76-
Usage
77-
-----
78-
79-
UX Vue.js works by using a system of **Vue.js controller components**: Vue.js components that
80-
are registered using ``registerVueControllerComponents`` and that are meant to be rendered
81-
from Twig.
57+
registerVueControllerComponents(require.context('./vue/controllers', true, /\\.(j|t)sx?$/));
8258
83-
When using the ``registerVueControllerComponents`` configuration shown previously, all
84-
Vue.js components located in the directory ``assets/vue/controllers`` are registered as
85-
Vue.js controller components.
59+
This will load all Vue components located in the ``assets/vue/controllers``
60+
directory. These are known as **Vue controller components**: top-level
61+
components that are meant to be rendered from Twig.
8662

87-
You can then render any Vue.js controller component in Twig using the ``vue_component``.
88-
For example:
63+
You can render any Vue controller component in Twig using the ``vue_component()``.
8964

9065
.. code-block:: javascript
9166
92-
// assets/vue/controllers/MyComponent.vue
67+
// assets/vue/controllers/Hello.vue
9368
<template>
9469
<div>Hello {{ name }}!</div>
9570
</template>
@@ -103,7 +78,7 @@ For example:
10378
.. code-block:: html+twig
10479

10580
{# templates/home.html.twig #}
106-
<div {{ vue_component('MyComponent', { 'name': app.user.fullName }) }}></div>
81+
<div {{ vue_component('Hello', { 'name': app.user.fullName }) }}></div>
10782

10883
Events
10984
~~~~~~

0 commit comments

Comments
 (0)