Skip to content

Commit 2622c68

Browse files
committed
ISSUE-345: vue.js fix
1 parent 74043a0 commit 2622c68

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,23 @@ This project adheres to a [Contributor Code of Conduct](CODE_OF_CONDUCT.md).
3939
By participating in this project and its community, you are expected to uphold
4040
this code.
4141

42-
## Command to running this project for local testing
43-
42+
## Commands for running this project for local testing
43+
```bash
44+
# Start the Symfony local server
4445
symfony local:server:start
45-
yarn encore dev
46+
```
47+
48+
```bash
49+
# Compile and watch assets (including Vue.js components)
50+
yarn encore dev --watch
51+
```
52+
53+
## Vue.js Integration
54+
This project uses Vue.js for interactive UI components. Vue components are located in the `assets/vue/` directory and are mounted to specific DOM elements:
55+
56+
- `App.vue` is mounted to the element with ID `vue-app`
57+
58+
To add new Vue components:
59+
1. Create the component in the `assets/vue/` directory
60+
2. Import and mount it in `assets/app.js`
61+
3. Add a mount point in the appropriate template

assets/app.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
import { createApp } from 'vue';
22
import App from './vue/App.vue';
3+
import MyWidget from './vue/MyWidget.vue';
34

4-
createApp(App).mount('#vue-app');
5+
// Mount the main app if the element exists
6+
const appElement = document.getElementById('vue-app');
7+
if (appElement) {
8+
createApp(App).mount('#vue-app');
9+
}
10+
11+
// Mount the widget if the element exists
12+
const widgetElement = document.getElementById('my-widget');
13+
if (widgetElement) {
14+
createApp(MyWidget).mount('#my-widget');
15+
}

assets/vue/MyWidget.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<div>
3+
<h2>Hello from MyWidget</h2>
4+
<p>{{ message }}</p>
5+
</div>
6+
</template>
7+
8+
<script>
9+
export default {
10+
name: 'MyWidget',
11+
data() {
12+
return {
13+
message: 'This is a reusable component!'
14+
}
15+
}
16+
}
17+
</script>

config/packages/twig.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ twig:
22
debug: '%kernel.debug%'
33
strict_variables: '%kernel.debug%'
44
default_path: '%kernel.application_dir%/templates'
5+
auto_reload: true

templates/security/login.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@
2525
<button type="submit" class="btn btn-primary btn-block">Sign in</button>
2626
</form>
2727
</div>
28+
<div id="my-widget"></div>
2829
{% endblock %}

0 commit comments

Comments
 (0)