Answer the question
In order to leave comments, you need to log in
How to include jquery in vue component?
My component
<template>
<div>Шапка</div>
</template>
<script>
import cookies from 'js-cookie'
export default {
name: 'navigation',
props: ['backend'],
data() {
return {
isLogin: !!cookies.get('user')
}
},
methods: {
login() {
this.$store.commit('global/showLoginModal', true)
},
search(e) {
var qs = e.target.value
if (qs === '') {
return false
}
this.$router.replace('/search/' + qs)
}
}
}
</script>
var searchBar = $(".search"),
searchInput = searchBar.find("input"),
searchToggleBtn = $(".search-toggle"),
searchParent = $("header_content");
searchInput.on("focus", function() {
searchBar.addClass("expanded")
}), searchInput.on("blur", function() {
$(this).val() || searchBar.removeClass("expanded")
}), searchToggleBtn.on("click", function() {
$(this).toggleClass("active"), searchParent.toggleClass("search"), searchBar.toggleClass("visible"), searchInput.focus()
});
Answer the question
In order to leave comments, you need to log in
You don't need jQuery to pull so much unnecessary code.
Seems like it should work
let searchBar = document.querySelector('.search'),
searchInput = searchBar.querySelector('input'),
searchToggleBtn = document.querySelector('.search-toggle'),
searchParent = document.querySelector('.header_content');
searchInput.addEventListener('focus', function (event) {
searchBar.classList.add('expanded');
});
searchInput.addEventListener('blur', function (event) {
searchInput.value || searchBar.classList.remove('expanded');
});
searchToggleBtn.addEventListener('click', function (event) {
searchToggleBtn.classList.toggle('active');
searchParent.classList.toggle('search');
searchBar.classList.toggle('visible');
searchInput.focus();
});
As an option, like this:
import JQuery from 'jquery'
let $ = JQuery
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question