<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Muhammet ESER</title>
    <description>The latest articles on DEV Community by Muhammet ESER (@eserdinyo).</description>
    <link>https://dev.to/eserdinyo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F207947%2F7b7aa363-7c2b-444b-af03-8d11f4ca589b.png</url>
      <title>DEV Community: Muhammet ESER</title>
      <link>https://dev.to/eserdinyo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eserdinyo"/>
    <language>en</language>
    <item>
      <title>Best way to using vue-clickaway in Nuxt.</title>
      <dc:creator>Muhammet ESER</dc:creator>
      <pubDate>Tue, 03 Nov 2020 18:12:00 +0000</pubDate>
      <link>https://dev.to/eserdinyo/best-way-to-using-vue-clickaway-in-nuxt-4170</link>
      <guid>https://dev.to/eserdinyo/best-way-to-using-vue-clickaway-in-nuxt-4170</guid>
      <description>&lt;p&gt;In this article, I will show you to the best way of using vue-clickaway package in nuxt project.&lt;/p&gt;

&lt;p&gt;First of all, if you are need to use this package in only one place you can just use it regular way as in the documentation.&lt;/p&gt;

&lt;p&gt;But if you have a big project and you will use so many places you should see this usage.&lt;/p&gt;

&lt;p&gt;Firstly you should install vue-clickaway.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;yarn add vue-clickaway
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, we will create a nuxt plugin. Let's give it a name like &lt;code&gt;clickaway.js&lt;/code&gt;. It's totally up to you.&lt;/p&gt;

&lt;p&gt;We will use vue's Global Mixin feature for using the vue-clickway to global. You can take a look to &lt;a href="https://vuejs.org/v2/guide/mixins.html#Global-Mixin"&gt;docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Lets add the following code to our &lt;code&gt;clickaway.js&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;mixin&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;clickaway&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-clickaway&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mixin&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;mixins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;clickaway&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we should register this plugin to our &lt;code&gt;nuxt.config.js&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="nx"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;~/plugins/clickaway&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And our clickaway plugin is ready to use. You can use it anywhere you want in your project like in the example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;v-on-clickaway=&lt;/span&gt;&lt;span class="s"&gt;"closeMenu"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Some text...&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;          
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See you on the next tip. Have a nice coding ✌️&lt;/p&gt;

</description>
      <category>nuxt</category>
      <category>vue</category>
      <category>javascript</category>
      <category>clickaway</category>
    </item>
  </channel>
</rss>
