Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vue
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lib
unicaen
vue
Commits
cfa077b5
Commit
cfa077b5
authored
4 months ago
by
Laurent Lecluse
Browse files
Options
Downloads
Patches
Plain Diff
[Fix] Les composants Vue sont aussi chargés à l'intérieur de HTML renvoyé en Ajax
parent
58a7d96b
Branches
Branches containing commit
Tags
8.1beta
Tags containing commit
No related merge requests found
Pipeline
#33583
passed
4 months ago
Stage: publish
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+6
-0
6 additions, 0 deletions
CHANGELOG.md
js/Client/main.js
+37
-15
37 additions, 15 deletions
js/Client/main.js
with
43 additions
and
15 deletions
CHANGELOG.md
+
6
−
0
View file @
cfa077b5
CHANGELOG
=========
6.
2.6 (07/01/2025)
------------------
-
[Fix] Les composants Vue sont aussi chargés à l'intérieur de HTML renvoyé en Ajax
6.2.5 (19/09/2024)
------------------
...
...
This diff is collapsed.
Click to expand it.
js/Client/main.js
+
37
−
15
View file @
cfa077b5
import
{
createApp
}
from
'
vue
'
;
import
{
createBootstrap
}
from
'
bootstrap-vue-next
'
;
// on met en place le client d'UnicaenVue
import
unicaenVue
from
'
./unicaenVue
'
;
function
init
(
vues
,
options
)
{
const
components
=
{}
const
components
=
{}
;
if
(
undefined
===
options
)
{
options
=
{};
}
// Convertir les chemins des composants en noms de composants
for
(
const
path
in
vues
)
{
let
compPath
=
path
.
slice
(
2
,
-
4
);
let
compName
=
compPath
.
replaceAll
(
'
/
'
,
''
);
components
[
compName
]
=
vues
[
path
].
default
;
}
//
instantiate the Vue apps
// Note our lookup is a wrapping div with .vue-app class
for
(
const
el
of
document
.
getElementsByClassName
(
'
vue-app
'
))
{
//
Fonction pour initialiser une application Vue sur un élément
function
mountVueApp
(
el
)
{
let
app
=
createApp
({
template
:
el
.
innerHTML
,
components
:
components
...
...
@@ -31,24 +29,48 @@ function init(vues, options)
options
.
beforeMount
(
app
);
}
//
a
utoload de
tous le
s composants déclarés
//
A
utoload des composants déclarés
if
(
undefined
!==
options
.
autoloads
)
{
for
(
const
alias
in
options
.
autoloads
)
{
let
compName
=
options
.
autoloads
[
alias
].
replaceAll
(
'
/
'
,
''
);
app
.
component
(
alias
,
components
[
compName
]);
}
}
app
.
use
(
createBootstrap
({
components
:
true
,
directives
:
true
}))
app
.
use
(
createBootstrap
({
components
:
true
,
directives
:
true
}))
;
app
.
mount
(
el
);
if
(
undefined
!==
options
.
afterMount
)
{
options
.
afterMount
(
app
);
}
}
// Initialiser les applications Vue sur les éléments existants
for
(
const
el
of
document
.
getElementsByClassName
(
'
vue-app
'
))
{
mountVueApp
(
el
);
}
// Observer les changements du DOM pour détecter les nouveaux éléments chargés en AJAX
const
observer
=
new
MutationObserver
((
mutationsList
)
=>
{
for
(
const
mutation
of
mutationsList
)
{
if
(
mutation
.
type
===
'
childList
'
)
{
// Vérifier si de nouveaux éléments avec la classe .vue-app ont été ajoutés
for
(
const
node
of
mutation
.
addedNodes
)
{
if
(
node
.
nodeType
===
Node
.
ELEMENT_NODE
&&
node
.
classList
.
contains
(
'
vue-app
'
))
{
mountVueApp
(
node
);
}
}
}
}
});
// Démarrer l'observation du DOM
observer
.
observe
(
document
.
body
,
{
childList
:
true
,
// Observer les ajouts/suppressions d'enfants
subtree
:
true
,
// Observer tout le sous-arbre du DOM
});
}
export
default
{
init
}
\ No newline at end of file
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment