feat: init directive

This commit is contained in:
Javier Segarra 2024-12-06 13:35:35 +01:00
parent dcbaa7529d
commit 3948b26f6b
2 changed files with 19 additions and 0 deletions

17
src/boot/dataCy.js Normal file
View File

@ -0,0 +1,17 @@
export default {
mounted: function (el, binding, { ctx }) {
const { innerText, localName } = el;
const { type, attrs } = ctx;
el.setAttribute(
'data-cy',
`${attrs?.label ?? innerText}_${type.name.replace('Q', '').toLowerCase()}`
);
console.error('dataCy', el.getAttribute('data-cy'));
},
unmounted: function (el) {
if (el._handleKeydown) {
window.removeEventListener('keydown', el._handleKeydown);
}
},
};

View File

@ -3,12 +3,14 @@ import qFormMixin from './qformMixin';
import keyShortcut from './keyShortcut'; import keyShortcut from './keyShortcut';
import useNotify from 'src/composables/useNotify.js'; import useNotify from 'src/composables/useNotify.js';
import { CanceledError } from 'axios'; import { CanceledError } from 'axios';
import dataCy from './dataCy';
const { notify } = useNotify(); const { notify } = useNotify();
export default boot(({ app }) => { export default boot(({ app }) => {
app.mixin(qFormMixin); app.mixin(qFormMixin);
app.directive('shortcut', keyShortcut); app.directive('shortcut', keyShortcut);
app.directive('dataCy', dataCy);
app.config.errorHandler = (error) => { app.config.errorHandler = (error) => {
let message; let message;
const response = error.response; const response = error.response;