<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>created &#8211; The SIGMA</title>
	<atom:link href="https://danushka96.github.io/sigma/index.php/tag/created/feed/" rel="self" type="application/rss+xml" />
	<link>https://danushka96.github.io/sigma/</link>
	<description>&#60;For Those Who Code/&#62;</description>
	<lastBuildDate>
	Sat, 02 Mar 2019 16:57:34 +0000	</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.1.1</generator>
	<item>
		<title>VueJs 2 &#8211; 05 filters and computed properties</title>
		<link>https://danushka96.github.io/sigma/index.php/2018/04/20/vuejs-2-05/</link>
				<comments>https://danushka96.github.io/sigma/index.php/2018/04/20/vuejs-2-05/#comments</comments>
				<pubDate>Fri, 20 Apr 2018 16:41:53 +0000</pubDate>
		<dc:creator><![CDATA[Prasad Kavinda]]></dc:creator>
				<category><![CDATA[VueJs]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[computed]]></category>
		<category><![CDATA[created]]></category>
		<category><![CDATA[filters]]></category>
		<category><![CDATA[mounted]]></category>
		<category><![CDATA[Vue]]></category>

		<guid isPermaLink="false">https://danushka96.github.io/sigma/?p=899</guid>
				<description><![CDATA[<p><span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">3</span> <span class="rt-label rt-postfix">minutes</span></span> හැමෝටම ආයුබෝවන්, VueJs ගැන කරන 5 වෙනි post එක. අද කියන්න යන්නෙ computed properties සහ filters ගැන. කලින් posts බැලුවෙ නැත්තම් මෙතනින් ගිහින් බලන්න. ගොඩක් වෙලාවට අපි app එකක් හදද්දි, app එකේ භාවිතාවෙන data වලට විවිද operations කරන්න සිදුවෙනව. උදාහරණයක් විදියට මෙහෙම හිතන්නකො. අපේ app එකේ firstName, lastName කියල data<a class="moretag" href="https://danushka96.github.io/sigma/index.php/2018/04/20/vuejs-2-05/"> Read more&#8230;</a></p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/04/20/vuejs-2-05/">VueJs 2 &#8211; 05 filters and computed properties</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></description>
								<content:encoded><![CDATA[<span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">3</span> <span class="rt-label rt-postfix">minutes</span></span><p>හැමෝටම ආයුබෝවන්, VueJs ගැන කරන 5 වෙනි post එක. අද කියන්න යන්නෙ computed properties සහ filters ගැන.<span style="font-weight: 400;"> කලින් posts බැලුවෙ නැත්තම් <a href="https://danushka96.github.io/sigma/index.php/category/vuejs/">මෙතනින් </a>ගිහින් බලන්න. </span></p>
<p>ගොඩක් වෙලාවට අපි app එකක් හදද්දි, app එකේ භාවිතාවෙන data වලට විවිද operations කරන්න සිදුවෙනව. උදාහරණයක් විදියට මෙහෙම හිතන්නකො. අපේ app එකේ firstName, lastName කියල data 2ක් තියෙනව.</p>
<pre>data: {
    firstName: 'John',
    lastName: 'Doe'
}
</pre>
<p>දැන් අපිට කොහේදි හරි full name එක පාවිච්චි කරන්න ඕන උනොත්,</p>
<pre>firstName + ' ' + LastName</pre>
<p>කියල ලියන්න වෙනව. මේක එච්චර අමාරු දෙයක් නෙවෙයි කියල ඔයාලට හිතේවි. ඒත් මීට වඩා ලොකු/සංකීර්ණ විදියෙ operations/calculations කරන්න උනාම, සහ ඒව නැවත නැවත ලියන්න උනාම, මේක සෑහෙන්න වදයක් වෙනව. ඒවගේම app එකක, template එකේම logic(calculations) එකත් ලියන එක එච්චර හොඳ දෙයක් නෙවෙයි. මොකද එහෙම සේරම mix එකේ ලිව්වම maintain කරන්න අමාරු වෙනව. ඉතිං ඔන්න ඔය වගේ හේතු නිසා තමයි Vue වල computed property කියල එකක් තියෙන්නෙ. computed property ත් හරියට methods වගේ.(<a href="https://danushka96.github.io/sigma/index.php/2018/04/11/vuejs-2-02/" target="blank">2වෙනි post එකේ</a> මම methods ගැන කිව්ව මතක ඇති) Vue object එක ඇතුලෙ computed කියල object එකක මේ computed properties ලියන්න පුළුවන්. කලින් උදාහරණයම ගත්තොත් මේ වගේ ලියන්න පුළුවන්.</p>
<pre>const app = new Vue({
    el: '#my-app',
    data: {
        firstName: 'John',
        lastName: 'Doe'
    },
    computed: {
    	fullName: function () {
    	    return this.firstName + ' ' + this.lastName
    	}
    }
});
</pre>
<p>දැන් අපිට මේ fullName කියන එක සාමාන්‍ය data එකක් වගේම භාවිතා කරන්න පුළුවන්.</p>
<pre>&lt;div id="my-app"&gt;
    &lt;h1&gt; Hey, {{ fullName }} &lt;/h1&gt;
&lt;/div&gt;
</pre>
<h4><span style="font-weight: 400;"><strong>Filters</strong></span></h4>
<p><span style="font-weight: 400;">Filters වලින් කරන්නෙ අපි භාවිතා කරන data අපිට අවශ්‍ය විදියට format කරගන්න එක.Vue object එක ඇතුලෙ, filters කියල object එකක තමයි මේ filters define කරන්න ඕනෙ. Functions විදියට තමයි මේව define කරන්නෙ. උදාහරණයක් විදියට අපි හිතමු String එකක් uppercase එකට format කරගන්න ඕනෙ කියල. ඒකට මේ විදියට filter එකක් define කරගන්න පුලුවන්.</span></p>
<pre>const app = new Vue({
    el: '#my-app',
    data: {
        firstName: 'John',
        lastName: 'Doe'
    },
    filters: {
    	toUpper: function (val) {
    	    return val.toUpperCase()
    	}
    }
});
</pre>
<p><span style="font-weight: 400;">දැන් මෙහෙම define කරපු filter එක මේ විදියට පාවිච්චි කරන්න පුලුවන්. </span></p>
<pre>&lt;div id="my-app"&gt;
&lt;h1&gt; Hey, {{ firstName | toUpper }}&lt;/h1&gt;
&lt;/div&gt;
</pre>
<p><span style="font-weight: 400;">මේ විදියට ලිව්වම වෙන්නෙ, firstName කියන එක toUpper කියන filter function එකේ, පළවෙනි argument එක විදියට pass වෙන එක. මේ විදියට filters කීපයක් උනත් භාවිතා කරන්න පුලුවන්. එතකොට පළවෙනි filter එකින් return වෙන data එක ඊළග filter එකට pass වෙනව.</span></p>
<p><span style="font-weight: 400;">මේ තියෙන්නෙ තව උදාහරණයක්. මේකෙදි data විදියට තියෙන්නෙ john, steve, dennis කියල objects 3 ක්. filters 2ක් define කරල තියෙනව. fullName කියන filter එකෙන් වෙන්නෙ ඒකට pass කරන object එක full name විදියට format කරන එක.</span></p>
<pre>const app = new Vue({
    el: '#my-app',
    data: {
        john: {firstName: 'John', lastName: 'Doe'},
        steve: {firstName: 'Steve', lastName: 'Jobs'},
        dennis: {firstName: 'Dennis', lastName: 'Ritchie'}
    },
    filters: {
        fullName: function (val) {
            return val.firstName + ' ' + val.lastName
        },
        toUpper: function (val) {
            return val.toUpperCase()
        }
    }
});
</pre>
<pre>&lt;div id="my-app"&gt;
    &lt;h1&gt; Hey, {{ john | fullName }}&lt;/h1&gt;
    &lt;h1&gt; Hey, {{ steve | fullName | toUpper }}&lt;/h1&gt;
&lt;/div&gt;</pre>
<h4><strong>Created and mounted properties</strong></h4>
<p><span style="font-weight: 400;">Created සහ mounted කියන්නෙත් vue object එකට pass කරන්න පුළුවන් තවත් වැදගත් properties 2ක්. මේව functions. created function එක ඇතුලෙ ලියන codes, vue app එකම හෝ vue components (vue components ගැන ඊළග post එකේදි කියන්නම්) create උන ගමන්, ඉබේම run වෙනව. ඒ වගේම mounted function එක ඇතුලෙ ලියන codes, app/component එක mount උන ගමන්ම ඉබේම run වෙනව. මේවට පොදුවෙ කියන්නෙ life cycle hooks කියල. created/mounted විතරක් නෙවෙයි, beforeCreate, beforeMount, beforeUpdate, updated වගේ තව කීපයක්ම තියෙනව. හැබැයි මම කියන්න යන්නෙ created, mounted කියන 2 ගැන විතරයි. අනිත් ඒවත් මේ වගේම තමයි. මේ උදාහරණයෙන් ඒ දෙක ගැන තේරුම් ගන්න පුළුවන් වෙයි.</span></p>
<pre>const app = new Vue({
    created: function () {
        console.log('CREATED');
    },
    mounted: function () {
        console.log('MOUNTED');
    }
});
</pre>
<p><span style="font-weight: 400;">Browser එකේ console එක open කරල බලන්නකො.(<kbd>F12</kbd>) created function එකේ ලියපු console.log එක run වෙලා ⁣තියෙනව බලාගන්න පුලුවන්. හැබැයි mounted function එකේ තියෙන console.log එක run වෙලා නැහැ මොකද, අපි app එක කොහේටවත් mount කරල නැති නිසා.</span></p>
<p><img class="wp-image-927 aligncenter" src="https://danushka96.github.io/sigma/wp-content/uploads/2018/04/created-300x136.png" alt="created" width="794" height="360" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/04/created-300x136.png 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/04/created-768x347.png 768w, https://danushka96.github.io/sigma/wp-content/uploads/2018/04/created-1024x463.png 1024w, https://danushka96.github.io/sigma/wp-content/uploads/2018/04/created.png 1546w" sizes="(max-width: 794px) 100vw, 794px" /></p>
<p><span style="font-weight: 400;">දැන් Browser console එකේ පහල තියෙන command එක ගැහුවම, my-app කියන element එකට app එක mount වෙනව.</span></p>
<pre>app.$mount("#my-app")</pre>
<p><span style="font-weight: 400;">මේක console එකේ type කරල enter key එක ඔබන්න. දැන් ඔයාලට බලාගන්න පුලුවන් MOUNTED කියල print වෙනව.</span></p>
<p><img class="wp-image-928 aligncenter" src="https://danushka96.github.io/sigma/wp-content/uploads/2018/04/and-mounted-300x169.png" alt="mounted" width="768" height="433" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/04/and-mounted-300x169.png 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/04/and-mounted-768x433.png 768w, https://danushka96.github.io/sigma/wp-content/uploads/2018/04/and-mounted-1024x577.png 1024w, https://danushka96.github.io/sigma/wp-content/uploads/2018/04/and-mounted.png 1535w" sizes="(max-width: 768px) 100vw, 768px" /></p>
<p><span style="font-weight: 400;">App එක create වෙද්දිම app එකට අවශ්‍ය data, back-end එ⁣කෙන් AJAX request හරහා අරගන්නකොට වගේ, මේ created සහ mounted කියන functions වැදගත් වෙනව. මොකද, ඒකට අදාල code එක created කියන function එකේ ලිව්වම, app එක create වෙද්දිම ඒ code එක ඉබේම run වෙන නිසා, app එක create උන ගමන් ඒකට අවශ්‍ය data ඉබේම අරගන්නව.</span></p>
<p><span style="font-weight: 400;">අදට මෙතනින් ඉවරයි. ඊළග post එකෙන් බලමු Vue components කියන්නෙ මොනවද කියල. අදහස්, යෝජනා, ඡෝදනා, ප්‍රශ්න මොනවහරිම තියෙනම් comment එකක් දාන්න. 😀</span></p>
<p>ඊළඟ post එකට <a href="https://danushka96.github.io/sigma/index.php/2018/04/22/vuejs-2-06">මෙතනින්</a> යන්න.</p>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/04/20/vuejs-2-05/">VueJs 2 &#8211; 05 filters and computed properties</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></content:encoded>
							<wfw:commentRss>https://danushka96.github.io/sigma/index.php/2018/04/20/vuejs-2-05/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
							</item>
	</channel>
</rss>
