Vue.js Integration
ColdBox Elixir lets you work with .vue
files out of the box.
You will begin by installing Vue.js via npm: npm install vue
. This will add Vue
as a dependency for your project in your project's package.json
and into the node_modules
directory. The following is the package.json
you should use when integrating with Vue.js:
package.json
Then create your normal JavaScript and Vue components in your resources/assets/js
folder.
Your App.js
can look like this:
resources/assets/js/App.js
And you can import any components following the same relative path of the resources/assets/js
folder.
You can also use the optional .vue
syntax which allows you to co-locate your template, styles, and scripts in a single-file component.
resources/assets/js/App.js
resources/assets/js/components/Profile.vue
You would then use this in your ColdBox layout or view like so:
Any style blocks in your .vue
components will be extracted as well to the same directory as your javascript file as a css file. For example, if you were compiling mix.vue( "app.js" )
Elixir would generate a includes/js/app.css
file containing the css for the style blocks used in that entrypoint.
Note: there are some drawbacks with style blocks in Vue components and Elixir. if you are creating multiple entry points with multiple
mix.vue
calls, any style blocks in shared components will be duplicated in each of the css files. Additionally, because Elixir is already extracting other css files, style blocks in Vue components are always extracted. For these reasons, we recommend using other approaches to managing your css with Vue components and Elixir.
Last updated