<?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>Forem: Winner Crespo</title>
    <description>The latest articles on Forem by Winner Crespo (@winnercrespo).</description>
    <link>https://forem.com/winnercrespo</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%2F86152%2Fbb7bc7a8-59b7-477f-83f4-dd0ec2e6cc1d.jpg</url>
      <title>Forem: Winner Crespo</title>
      <link>https://forem.com/winnercrespo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/winnercrespo"/>
    <language>en</language>
    <item>
      <title>Learning the position CSS property for good</title>
      <dc:creator>Winner Crespo</dc:creator>
      <pubDate>Wed, 27 Jun 2018 00:00:00 +0000</pubDate>
      <link>https://forem.com/winnercrespo/learning-the-position-css-property-for-good-548</link>
      <guid>https://forem.com/winnercrespo/learning-the-position-css-property-for-good-548</guid>
      <description>&lt;p&gt;When I create a layout from scratch, I find myself adding different values to the &lt;code&gt;position&lt;/code&gt; CSS property and to the DPP (direction position properties, I just made that acronym up) top, right, bottom and left properties, hoping that magically they will look as I expect. Maybe you do too.&lt;/p&gt;

&lt;p&gt;It would probably be better to learn what they do for good, so we know how to use them.&lt;/p&gt;

&lt;p&gt;First of all, a positioned element is one that has a different value than &lt;code&gt;position: static&lt;/code&gt;, which is the default. In other words, an element that has &lt;code&gt;position&lt;/code&gt; set as &lt;code&gt;relative&lt;/code&gt;, &lt;code&gt;absolute&lt;/code&gt;, &lt;code&gt;fixed&lt;/code&gt; or &lt;code&gt;sticky&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Having that said, we can state that &lt;code&gt;position&lt;/code&gt; defines how an element is positioned on the page. On the other hand, the DPP add an offset on the direction they specify.&lt;/p&gt;

&lt;p&gt;Let’s see how each one works.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;static&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This is the default value and means that the element will be placed according to the page flow. Because of that, the DPP don’t affect it.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;relative&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The element will also be placed according to the page flow but now you can use the DPP to add an offset relative to itself. As we can see in the animation below, the space this element is supposed to use is reserved and other elements are not affected even after adding an offset.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/wistcc/embed/mjXgjq?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;absolute&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;You can use this value to place an element exactly where you want it, also, the element is removed from the page flow. This position will be relative to the next parent element with &lt;code&gt;relative&lt;/code&gt; or &lt;code&gt;absolute&lt;/code&gt; positioning. If there is no such parent, it will be placed relative to the page itself as the next example.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/wistcc/embed/BPYEOV?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;fixed&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The element is positioned relative to the viewport since the viewport doesn’t change when scrolling, the element will be fixed exactly where you placed it. Also, just like &lt;code&gt;absolute&lt;/code&gt;, the element is removed from the page flow and it will be relative to the next parent element with &lt;code&gt;relative&lt;/code&gt; or &lt;code&gt;absolute&lt;/code&gt; positioning.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/wistcc/embed/EpQJdP?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;sticky&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;It behaves like the &lt;code&gt;fixed&lt;/code&gt; value but relative to itself since the element is placed according to the page flow. In the example, we can notice that once we are able to see the element and we keep scrolling it will be fixed.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/wistcc/embed/bjLJmm?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;I hope that now you are able to use those properties knowing exactly what they do.&lt;/p&gt;

&lt;p&gt;Happy coding.&lt;/p&gt;

</description>
      <category>css</category>
      <category>devtips</category>
      <category>beginners</category>
      <category>explainlikeimfive</category>
    </item>
    <item>
      <title>Things that won’t work using Vue</title>
      <dc:creator>Winner Crespo</dc:creator>
      <pubDate>Sun, 17 Jun 2018 00:00:00 +0000</pubDate>
      <link>https://forem.com/winnercrespo/things-that-wont-work-using-vue-384e</link>
      <guid>https://forem.com/winnercrespo/things-that-wont-work-using-vue-384e</guid>
      <description>&lt;p&gt;After using Vue for a while, I have found some issues that later I learned are actually things they warned us in the documentation.&lt;/p&gt;

&lt;p&gt;I made a list of these issues so you can know them as well. Let’s describe each and see the options we have to solve them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Array Changes
&lt;/h2&gt;

&lt;p&gt;Let’s say we have this:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;vm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;titles&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;Ready Player One&lt;/span&gt;&lt;span class="dl"&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;The Power of Less&lt;/span&gt;&lt;span class="dl"&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;The 10x rule&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;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can get two different issues while trying to do changes to &lt;code&gt;titles&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Setting an item using the index: &lt;code&gt;vm.titles[index] = newTitle&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Modifying the length: &lt;code&gt;vm.titles.length = length&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of setting an item using the index directly you can use &lt;code&gt;Vue.set&lt;/code&gt;:&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;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;titles&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;newTitle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another alternative is using &lt;code&gt;splice&lt;/code&gt;:&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;vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;titles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;newTitle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the other hand, to modify the length you can use &lt;code&gt;splice&lt;/code&gt; as well:&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;vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;titles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Adding properties to an object
&lt;/h2&gt;

&lt;p&gt;Having the following object:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;vm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;bestMovie&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Avengers: Infinity War&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;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We could be tempted to add a new property doing the next:&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;vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bestShow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Breaking Bad&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but then &lt;code&gt;bestShow&lt;/code&gt; won’t be reactive because Vue adds the reactive functionality at the moment of the initialization. Which means that the property must be in the &lt;code&gt;data&lt;/code&gt; object in order to be reactive.&lt;/p&gt;

&lt;p&gt;We can use &lt;code&gt;Vue.set&lt;/code&gt; again to accomplish this:&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;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bestShow&lt;/span&gt;&lt;span class="dl"&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;Breaking Bad&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Although, if you need to add several properties, maybe would be better to create a fresh object combining them:&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;vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;assign&lt;/span&gt;&lt;span class="p"&gt;({},&lt;/span&gt; &lt;span class="nx"&gt;vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;bestShow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Breaking Bad&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;bestBook&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ready Player One&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using &lt;code&gt;$refs&lt;/code&gt; before the component is mounted
&lt;/h2&gt;

&lt;p&gt;Let’s say we want to focus an input on our component. We could use the &lt;code&gt;ref&lt;/code&gt; attribute for that:&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then:&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;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;focusInput&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$refs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;focus&lt;/span&gt;&lt;span class="p"&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;What if we want to focus it as soon as the component is created? You would say that we could use the &lt;code&gt;created&lt;/code&gt; hook:&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;created&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$refs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;focus&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;but actually, this produces an error because &lt;code&gt;$refs&lt;/code&gt; is populated after the component has been mounted. So, we should use the &lt;code&gt;mounted&lt;/code&gt; hook instead since it will be already populated:&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;mounted&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$refs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;focus&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;h2&gt;
  
  
  Toggling similar elements
&lt;/h2&gt;

&lt;p&gt;Vue sometimes will reuse elements that have the same tag name when using &lt;code&gt;v-if&lt;/code&gt; on them. As you can see in the next example, the input element is reused when the toggle button is pressed.&lt;/p&gt;

&lt;p&gt;To notice this you can write something in the input and then press the button (the value won’t change) or you can use the dev tools and see that the element is not replaced:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/wistcc/embed/OwgbMg?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;br&gt;
 &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KV2IsnIX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://winnercrespo.com/assets/images/2018-6-21-things-that-wont-work-using-vue-1.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KV2IsnIX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://winnercrespo.com/assets/images/2018-6-21-things-that-wont-work-using-vue-1.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To solve this we just need to add a key to each of them so Vue knows they are distinct elements:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/wistcc/embed/PBjbNm?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;br&gt;
 &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bf1mn2Z1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://winnercrespo.com/assets/images/2018-6-21-things-that-wont-work-using-vue-2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bf1mn2Z1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://winnercrespo.com/assets/images/2018-6-21-things-that-wont-work-using-vue-2.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we can see that the element is replaced every time we click the button.&lt;/p&gt;

&lt;p&gt;Have you noticed other things that won’t work on Vue? Please share in the comments.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>vue</category>
      <category>beginners</category>
      <category>explainlikeimfive</category>
    </item>
    <item>
      <title>Why does the data property on a Vue component must be a function?</title>
      <dc:creator>Winner Crespo</dc:creator>
      <pubDate>Wed, 13 Jun 2018 00:00:00 +0000</pubDate>
      <link>https://forem.com/winnercrespo/why-does-the-data-property-on-a-vue-component-must-be-a-function-566c</link>
      <guid>https://forem.com/winnercrespo/why-does-the-data-property-on-a-vue-component-must-be-a-function-566c</guid>
      <description>&lt;p&gt;If you don’t get familiar with the basic rules of a framework (programming language, tool, etc) when starting to use it, things won’t work as expected, since it wasn’t conceived that way.&lt;/p&gt;

&lt;p&gt;While using Vue for the first time, I made this by mistake:&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;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Some Message&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then, I got the following warning message:&lt;/p&gt;

&lt;p&gt;[Vue warn]: The “data” option should be a function that returns a per-instance value in component definitions.&lt;/p&gt;

&lt;p&gt;What you should do instead is:&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;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Some Message&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;So, the reason why Vue forces the data property to be a function is that each instance of a component should have its own data object. If we don’t do that, all instances will be sharing the same object and every time we change something, it will be reflected in all instances.&lt;/p&gt;

&lt;p&gt;Check out what the &lt;a href="https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function"&gt;Vue’s documentation&lt;/a&gt; says about it and a quick live example.&lt;/p&gt;

&lt;p&gt;I hope this helps.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>vue</category>
      <category>beginners</category>
      <category>explainlikeimfive</category>
    </item>
  </channel>
</rss>
