<?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: Tran Dinh Hieu (Wilson Tran)</title>
    <description>The latest articles on DEV Community by Tran Dinh Hieu (Wilson Tran) (@willson_tran).</description>
    <link>https://dev.to/willson_tran</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3046324%2F928dcbd2-81ac-44b1-90b4-74524b724c10.jpg</url>
      <title>DEV Community: Tran Dinh Hieu (Wilson Tran)</title>
      <link>https://dev.to/willson_tran</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/willson_tran"/>
    <language>en</language>
    <item>
      <title>VueJS - JavaScript Framework</title>
      <dc:creator>Tran Dinh Hieu (Wilson Tran)</dc:creator>
      <pubDate>Sun, 13 Apr 2025 05:37:11 +0000</pubDate>
      <link>https://dev.to/willson_tran/javascript-framework-day-1-1n</link>
      <guid>https://dev.to/willson_tran/javascript-framework-day-1-1n</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Furokv9obeea8stai4d2u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Furokv9obeea8stai4d2u.png" alt="Image description" width="369" height="136"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is Vue?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Vue is a JavaScript framework for building UIs. It builds on top of standard HTML, CSS, and JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Single-File Components&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In most build-tool-enabled Vue projects, we author Vue components using an HTML-like file format called Single-File Component (also known as *.vue files, abbreviated as SFC). A Vue SFC, as the name suggests, encapsulates the component's logic (JavaScript), template (HTML), and styles (CSS) in a single file. Here's the previous example, written in SFC format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script setup&amp;gt;
import { ref } from 'vue'
const count = ref(0)
&amp;lt;/script&amp;gt;

&amp;lt;template&amp;gt;
  &amp;lt;button @click="count++"&amp;gt;Count is: {{ count }}&amp;lt;/button&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;style scoped&amp;gt;
button {
  font-weight: bold;
}
&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;API Styles&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Vue components can be authored in two different API styles: Options API and Composition API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Options API&lt;/strong&gt;&lt;br&gt;
With Options API, we define a component's logic using an object of options such as data, methods, and mounted. Properties defined by options are exposed on this inside functions, which points to the component instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
export default {
  // Properties returned from data() become reactive state
  // and will be exposed on `this`.
  data() {
    return {
      count: 0
    }
  },

  // Methods are functions that mutate state and trigger updates.
  // They can be bound as event handlers in templates.
  methods: {
    increment() {
      this.count++
    }
  },

  // Lifecycle hooks are called at different stages
  // of a component's lifecycle.
  // This function will be called when the component is mounted.
  mounted() {
    console.log(`The initial count is ${this.count}.`)
  }
}
&amp;lt;/script&amp;gt;

&amp;lt;template&amp;gt;
  &amp;lt;button @click="increment"&amp;gt;Count is: {{ count }}&amp;lt;/button&amp;gt;
&amp;lt;/template&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Composition API&lt;/strong&gt;&lt;br&gt;
With Composition API, we define a component's logic using imported API functions. &lt;/p&gt;

&lt;p&gt;Here is the same component, with the exact same template, but using Composition API instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script setup&amp;gt;
import { ref, onMounted } from 'vue'

// reactive state
const count = ref(0)

// functions that mutate state and trigger updates
function increment() {
  count.value++
}

// lifecycle hooks
onMounted(() =&amp;gt; {
  console.log(`The initial count is ${count.value}.`)
})
&amp;lt;/script&amp;gt;

&amp;lt;template&amp;gt;
  &amp;lt;button @click="increment"&amp;gt;Count is: {{ count }}&amp;lt;/button&amp;gt;
&amp;lt;/template&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  *&lt;em&gt;Which to choose?&lt;/em&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For learning purpose:&lt;br&gt;
Go with the style that looks easier to understand to you. Again, most of the core concepts are shared between the two styles. You can always pick up the other style later.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For production use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go with Options API if you are not using build tools, or plan to use Vue primarily in low-complexity scenarios, e.g. progressive enhancement.&lt;/li&gt;
&lt;li&gt;Go with Composition API + Single-File Components if you plan to build full applications with Vue.*&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

</description>
    </item>
  </channel>
</rss>
