Language switcher с анимацыей
Здравствуйте, оцените пожалуйста етот код vue 2 cli + i18n
<template> <div v-focusOut tabindex="1" class="select" v-bind:class="{ 'select-dropped': isDroped }" > <div class="main" @click="isDroped = !isDroped"> <div class="option">Choose</div> </div> <div class="dropdown-wrapper" v-dropped> <div class="dropdown"> <div class="option" @click="select('en-US', $event)"> English </div> <div class="option" @click="select('ru-RU', $event)"> <svg xmlns="http://www.w3.org/2000/svg" height="100%" viewBox="0 0 640 480" > <g fill-rule="evenodd"> <g stroke-width="1pt"> <path fill="#bd3d44" d="M0 0h972.8v39.4H0zm0 78.8h972.8v39.4H0zm0 78.7h972.8V197H0zm0 78.8h972.8v39.4H0zm0 78.8h972.8v39.4H0zm0 78.7h972.8v39.4H0zm0 78.8h972.8V512H0z" transform="scale(.9375)" /> <path fill="#fff" d="M0 39.4h972.8v39.4H0zm0 78.8h972.8v39.3H0zm0 78.7h972.8v39.4H0zm0 78.8h972.8v39.4H0zm0 78.8h972.8v39.4H0zm0 78.7h972.8v39.4H0z" transform="scale(.9375)" /> </g> <path fill="#192f5d" d="M0 0h389.1v275.7H0z" transform="scale(.9375)" /> <path fill="#fff" d="M32.4 11.8L36 22.7h11.4l-9.2 6.7 3.5 11-9.3-6.8-9.2 6.7 3.5-10.9-9.3-6.7H29zm64.9 0l3.5 10.9h11.5l-9.3 6.7 3.5 11-9.2-6.8-9.3 6.7 3.5-10.9-9.2-6.7h11.4zm64.8 0l3.6 10.9H177l-9.2 6.7 3.5 11-9.3-6.8-9.2 6.7 3.5-10.9-9.3-6.7h11.5zm64.9 0l3.5 10.9H242l-9.3 6.7 3.6 11-9.3-6.8-9.3 6.7 3.6-10.9-9.3-6.7h11.4zm64.8 0l3.6 10.9h11.4l-9.2 6.7 3.5 11-9.3-6.8-9.2 6.7 3.5-10.9-9.2-6.7h11.4zm64.9 0l3.5 10.9h11.5l-9.3 6.7 3.6 11-9.3-6.8-9.3 6.7 3.6-10.9-9.3-6.7h11.5zM64.9 39.4l3.5 10.9h11.5L70.6 57 74 67.9l-9-6.7-9.3 6.7L59 57l-9-6.7h11.4zm64.8 0l3.6 10.9h11.4l-9.3 6.7 3.6 10.9-9.3-6.7-9.3 6.7L124 57l-9.3-6.7h11.5zm64.9 0l3.5 10.9h11.5l-9.3 6.7 3.5 10.9-9.2-6.7-9.3 6.7 3.5-10.9-9.2-6.7H191zm64.8 0l3.6 10.9h11.4l-9.3 6.7 3.6 10.9-9.3-6.7-9.2 6.7 3.5-10.9-9.3-6.7H256zm64.9 0l3.5 10.9h11.5L330 57l3.5 10.9-9.2-6.7-9.3 6.7 3.5-10.9-9.2-6.7h11.4zM32.4 66.9L36 78h11.4l-9.2 6.7 3.5 10.9-9.3-6.8-9.2 6.8 3.5-11-9.3-6.7H29zm64.9 0l3.5 11h11.5l-9.3 6.7 3.5 10.9-9.2-6.8-9.3 6.8 3.5-11-9.2-6.7h11.4zm64.8 0l3.6 11H177l-9.2 6.7 3.5 10.9-9.3-6.8-9.2 6.8 3.5-11-9.3-6.7h11.5zm64.9 0l3.5 11H242l-9.3 6.7 3.6 10.9-9.3-6.8-9.3 6.8 3.6-11-9.3-6.7h11.4zm64.8 0l3.6 11h11.4l-9.2 6.7 3.5 10.9-9.3-6.8-9.2 6.8 3.5-11-9.2-6.7h11.4zm64.9 0l3.5 11h11.5l-9.3 6.7 3.6 10.9-9.3-6.8-9.3 6.8 3.6-11-9.3-6.7h11.5zM64.9 94.5l3.5 10.9h11.5l-9.3 6.7 3.5 11-9.2-6.8-9.3 6.7 3.5-10.9-9.2-6.7h11.4zm64.8 0l3.6 10.9h11.4l-9.3 6.7 3.6 11-9.3-6.8-9.3 6.7 3.6-10.9-9.3-6.7h11.5zm64.9 0l3.5 10.9h11.5l-9.3 6.7 3.5 11-9.2-6.8-9.3 6.7 3.5-10.9-9.2-6.7H191zm64.8 0l3.6 10.9h11.4l-9.2 6.7 3.5 11-9.3-6.8-9.2 6.7 3.5-10.9-9.3-6.7H256zm64.9 0l3.5 10.9h11.5l-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 0l3.5 11H242l-9.3 6.7 3.6 10.8-9.3-6.7-9.3 6.7 3.6-10.9-9.3-6.7h11.4zm64.8 0l3.6 11h11.4l-9.2 6.7 3.5 10.8-9.3-6.7-9.2 6.7 3.5-10.9-9.2-6.7h11.4zm64.9 0l3.5 11h11.5l-9.3 6.7 3.6 10.8-9.3-6.7-9.3 6.7 3.6-10.9-9.3-6.7h11.5zM64.9 204.8l3.5 10.9h11.5l-9.3 6.7 3.5 11-9.2-6.8-9.3 6.7 3.5-10.9-9.2-6.7h11.4zm64.8 0l3.6 10.9h11.4l-9.3 6.7 3.6 11-9.3-6.8-9.3 6.7 3.6-10.9-9.3-6.7h11.5zm64.9 0l3.5 10.9h11.5l-9.3 6.7 3.5 11-9.2-6.8-9.3 6.7 3.5-10.9-9.2-6.7H191zm64.8 0l3.6 10.9h11.4l-9.2 6.7 3.5 11-9.3-6.8-9.2 6.7 3.5-10.9-9.3-6.7H256zm64.9 0l3.5 10.9h11.5l-9.3 6.7 3.5 11-9.2-6.8-9.3 6.7 3.5-10.9-9.2-6.7h11.4zM32.4 232.4l3.6 10.9h11.4l-9.2 6.7 3.5 10.9-9.3-6.7-9.2 6.7 3.5-11-9.3-6.7H29zm64.9 0l3.5 10.9h11.5L103 250l3.6 10.9-9.3-6.7-9.3 6.7 3.6-11-9.3-6.7h11.4zm64.8 0l3.6 10.9H177l-9 6.7 3.5 10.9-9.3-6.7-9.2 6.7 3.5-11-9.3-6.7h11.5zm64.9 0l3.5 10.9H242l-9.3 6.7 3.6 10.9-9.3-6.7-9.3 6.7 3.6-11-9.3-6.7h11.4zm64.8 0l3.6 10.9h11.4l-9.2 6.7 3.5 10.9-9.3-6.7-9.2 6.7 3.5-11-9.2-6.7h11.4zm64.9 0l3.5 10.9h11.5l-9.3 6.7 3.6 10.9-9.3-6.7-9.3 6.7 3.6-11-9.3-6.7h11.5z" transform="scale(.9375)" /> </g> </svg> Русский </div> </div> </div> </div> </template> <style lang="scss" scoped> $padding-width: 0vmin; $height-selected: 2vmin; $height-item: 2vmin; $transition: 0.4s; $border-radius: 0; .select { width: 15vmin; border-radius: $border-radius; background: white; cursor: pointer; position: relative; font-size: 1.6vmin; outline: none; border: none; padding: 0; .main { width: 100%; box-sizing: border-box; height: $height-selected; display: flex; align-items: center; padding: 0 $padding-width; .option { display: flex; height: $height-item; width: 100%; } .triange { position: absolute; right: $padding-width; width: $height-selected/2; height: $height-selected/2; transition: transform $transition ease-out; } .triangle-dropped { transform: rotateZ(180deg); } } .dropdown-wrapper { height: 0; overflow: hidden; transition: height $transition ease; .dropdown { overflow: hidden; .option { display: flex; height: $height-item; padding: 0 $padding-width; &:hover { background: red; } } } } } .select-dropped { padding-bottom: $border-radius; } </style> <script> export default { name: "LanguageSelector", data() { return { isDroped: false, }; }, methods: { select(locale, event) { event.currentTarget.parentElement.parentElement.parentElement.childNodes[0].childNodes[0].innerHTML = event.currentTarget.innerHTML; event.currentTarget.parentElement.parentElement.parentElement.dispatchEvent( new Event("focusout") ); this.$i18n.locale = locale; }, }, directives: { dropped(el, binding, vnode) { if (vnode.context.isDroped) { let width = document.documentElement.clientWidth; let height = document.documentElement.clientHeight; let minSide = height < width ? (minSide = height) : (minSide = width); el.style.height = (100 * el.firstChild.scrollHeight) / minSide + "vmin"; } else { el.style.height = 0; } }, focusOut: { inserted(el, binding, vnode) { el.addEventListener("focusout", () => { if (vnode.context.isDroped) { el.childNodes[1].childNodes[0].height = 0; vnode.context.isDroped = false; } }); }, }, }, }; </script> Насколько правильный подход использовать игры с parentElement и childNodes вместо id? Существует ли лучшый метод... Могу ли я както устанавливать значения scss переменных для компонента по одельности в каждой странице (чтоб к примеру на гловной странице $width:0; а на другой $width:1px) |
Часовой пояс GMT +3, время: 20:16. |