{"id":629,"date":"2022-03-29T12:27:08","date_gmt":"2022-03-29T12:27:08","guid":{"rendered":"http:\/\/shabeebk.com\/blog\/?p=629"},"modified":"2022-04-02T10:44:41","modified_gmt":"2022-04-02T10:44:41","slug":"simple-vue-composition-api-example-with-todo-app","status":"publish","type":"post","link":"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/","title":{"rendered":"Vue\u00a0composition API tutorial  with example"},"content":{"rendered":"\n<p>In this, I&#8217;ll show you how to vue2 composition API. <\/p>\n\n\n\n<p>Let us do a small example todo app  with Vue composition API<br>Vue 3 come up with Composition API, in Vue 2, we use The Options API, where we use uses&nbsp;<em>options<\/em>&nbsp;like&nbsp;<code>data<\/code>,&nbsp;<code>methods<\/code>, and&nbsp;<code>mounted<\/code>.  With the Composition API, we have a&nbsp;<code>setup<\/code>&nbsp;hook in which we write our reactive code and functions. <br>We can re-use the same functions in between components using Composition API, and save a lot of time.<\/p>\n\n\n\n<p>Demo: <a rel=\"noreferrer noopener\" href=\"https:\/\/vue-composition-api-simple-todo.pages.dev\/\" target=\"_blank\">https:\/\/vue-composition-api-simple-todo.pages.dev\/<\/a><br><\/p>\n\n\n\n<h2><strong>Setup and Installation<\/strong><\/h2>\n\n\n\n<p>We can install vueCLI and create a new project using  <code>vue create vue-composition-api-simple-todo<\/code>. Please refer to <a rel=\"noreferrer noopener\" href=\"http:\/\/shabeebk.com\/blog\/simple-vue-2-example-todo-list\/\" data-type=\"URL\" data-id=\"http:\/\/shabeebk.com\/blog\/simple-vue-2-example-todo-list\/\" target=\"_blank\">my previous post <\/a>in case you missed it.<br>Once we create our Vue project open the code base and let&#8217;s start with installing @vue\/composition-api<\/p>\n\n\n\n<h2>Install dependencies<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code> npm i  @vue\/composition-api --save<\/code><\/pre>\n\n\n\n<p>Let us take the same HTML from my last past, simple vue todo app  <a href=\"http:\/\/shabeebk.com\/blog\/simple-vue-2-example-todo-list\/\">Here<\/a> you can read it if you miss <\/p>\n\n\n\n<p>Let us import @vue\/composition-api and use it main.js<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import CompositionApi from '@vue\/composition-api'\nVue.use(CompositionApi)<\/code><\/pre>\n\n\n\n<h2>Start with coding<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>Full code of main.js looks like below<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import Vue from 'vue'\nimport App from '.\/App.vue'\nimport CompositionApi from '@vue\/composition-api'\n\nVue.config.productionTip = false\nVue.use(CompositionApi)\n\nnew Vue({\n  render: h =&gt; h(App),\n}).$mount('#app')\n<\/code><\/pre>\n\n\n\n<p>Let us create a new folder for composable functions<\/p>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-1812723430816589\" crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-1812723430816589\" data-ad-slot=\"6066985797\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<p>We can define Todos list in composable function like below<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { reactive } from \"@vue\/composition-api\";\nfunction useTodoList() {\n  let state = reactive({\n    newTodo: \"\",\n    todos: &#91;\n      {\n        id: 1,\n        title: \"Buy groceries for next week\",\n        completed: false,\n      },\n      {\n        id: 2,\n        title: \"Pay credit card bill \",\n        completed: false,\n      },\n    ],\n  });\n\n  return {\n    state, \n  };\n}\n\nexport default useTodoList<\/code><\/pre>\n\n\n\n<p>We use the same date, in composition functions, we will define state using <code><a href=\"https:\/\/vuejs.org\/api\/reactivity-core.html\">Reactivity API<\/a>, e.g.&nbsp;<code>ref()<\/code>&nbsp;and&nbsp;<code>reactive()<\/code>, that allows us to directly create reactive state, computed state, and watchers.<\/code><br>In this example, we use <code>reactive<\/code> to define the state and now we can use <code>todos<\/code> inside out template.<\/p>\n\n\n\n<p>in <code>components\/TodoList.vue<\/code> we can import composable function <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import useTodoList from \"@\/composable\/useTodoList\";\nexport default {\n  setup() {\n    const { state} = useTodoList();\n    return {\n      state,\n    };\n  },\n};\n<\/code><\/pre>\n\n\n\n<p>and we can use it in the template <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;tbody&gt;\n                    &lt;tr\n                     <strong> v-for=\"(todo, idx) in state.todos\"<\/strong>\n                      :key=\"todo.id\"\n                      :class=\"todo.completed &amp;&amp; 'stricked'\"\n                    &gt;\n                      &lt;th scope=\"row\"&gt;{{ idx + 1 }}&lt;\/th&gt;\n                      .....\n                    &lt;\/tr&gt;\n                  &lt;\/tbody&gt;<\/code><\/pre>\n\n\n\n<h2>Start the app<\/h2>\n\n\n\n<p>If we run the application we can see a list of todos \ud83d\ude42 <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM.png\"><img loading=\"lazy\" width=\"1024\" height=\"530\" src=\"http:\/\/shabeebk.com\/blog\/wp-content\/plugins\/jquery-image-lazy-loading\/images\/grey.gif\" data-original=\"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM.png\" alt=\"\" class=\"lazy wp-image-633\" srcset=\"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM.png 1024w, http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM-300x155.png 300w, http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM-768x398.png 768w, http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM-788x408.png 788w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><noscript><img loading=\"lazy\" width=\"1024\" height=\"530\" src=\"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM.png\" alt=\"\" class=\"wp-image-633\" srcset=\"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM.png 1024w, http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM-300x155.png 300w, http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM-768x398.png 768w, http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM-788x408.png 788w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/noscript><\/a><\/figure>\n\n\n\n<p>Let&#8217;s add more functionality like <code>addtodo<\/code> <code>toggleCompleted<\/code> and <code>removeItem<\/code> in <code>composable\/useTodoList.js<\/code>.<br>The final code looks like below<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { reactive } from \"@vue\/composition-api\";\nfunction useTodoList() {\n ......\n\n  <strong>function addToDo(e) {\n    console.log(\"state.newTodo\", state, state.newTodo);\n    e.preventDefault();\n    state.todos.push({\n      id: state.todos.length + 1,\n      title: state.newTodo,\n      completed: false,\n    });\n    state.newTodo = \"\";\n  }\n\n  function toggleCompleted(item) {\n    item.completed = !item.completed;\n  }\n  function removeItem(item) {\n    state.todos = state.todos.filter((newItem) =&gt; newItem.id !== item.id);\n  }<\/strong>\n  return {\n    state,\n   <strong> addToDo,\n    toggleCompleted,\n    removeItem,<\/strong>\n  };\n}\n\nexport default useTodoList<\/code><\/pre>\n\n\n\n<p>Let us import  <code>addtodo<\/code> <code>toggleCompleted<\/code> and <code>removeItem<\/code> in  <code>components\/TodoList.vue<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n&lt;script&gt;\nimport useTodoList from \"@\/composable\/useTodoList\";\nexport default {\n  setup() {\n    const { state, <strong>addToDo, toggleCompleted, removeItem<\/strong> } = useTodoList();\n    return {\n      state,\n     <strong> addToDo,\n      toggleCompleted,\n      removeItem,<\/strong>\n    };\n  },\n};\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p>How we can use it in the template?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>....\n                  &lt;div class=\"col-12\"&gt;\n                    &lt;button\n                      type=\"button\"\n                      class=\"btn btn-primary\"\n                      <strong>@click=\"addToDo\"<\/strong>\n                    &gt;\n                      Save\n                    &lt;\/button&gt;\n                  &lt;\/div&gt;\n\n                  .......\n\n                  &lt;tbody&gt;\n                    &lt;tr\n                      v-for=\"(todo, idx) in state.todos\"\n                      :key=\"todo.id\"\n                      :class=\"todo.completed &amp;&amp; 'stricked'\"\n                    &gt;\n                      &lt;th scope=\"row\"&gt;{{ idx + 1 }}&lt;\/th&gt;\n                      &lt;td&gt;{{ todo.title }}&lt;\/td&gt;\n                      &lt;td&gt;\n                        {{ todo.completed ? \"Completed\" : \"In progress\" }}\n                      &lt;\/td&gt;\n                      &lt;td&gt;\n                        &lt;button\n                          type=\"submit\"\n                          class=\"btn btn-danger\"\n                          <strong>@click=\"removeItem(todo)\"<\/strong>\n                        &gt;\n                          Delete\n                        &lt;\/button&gt;\n                        &lt;button\n                          type=\"submit\"\n                          class=\"btn btn-success ms-1\"\n                          <strong>@click=\"toggleCompleted(todo)\"<\/strong>\n                        &gt;\n                          {{ todo.completed ? \"Re-open\" : \"Complete\" }}\n                        &lt;\/button&gt;\n                      &lt;\/td&gt;\n                    &lt;\/tr&gt;\n                  &lt;\/tbody&gt;\n             \n             ....<\/code><\/pre>\n\n\n\n<p>Once we run the server, we can see add toggle and remove is working<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.42.59-PM.png\"><img loading=\"lazy\" width=\"1024\" height=\"543\" src=\"http:\/\/shabeebk.com\/blog\/wp-content\/plugins\/jquery-image-lazy-loading\/images\/grey.gif\" data-original=\"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.42.59-PM.png\" alt=\"vue composition api todo example\" class=\"lazy wp-image-635\" title=\"vue composition api todo example\" srcset=\"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.42.59-PM.png 1024w, http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.42.59-PM-300x159.png 300w, http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.42.59-PM-768x407.png 768w, http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.42.59-PM-788x418.png 788w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><noscript><img loading=\"lazy\" width=\"1024\" height=\"543\" src=\"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.42.59-PM.png\" alt=\"vue composition api todo example\" class=\"wp-image-635\" title=\"vue composition api todo example\" srcset=\"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.42.59-PM.png 1024w, http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.42.59-PM-300x159.png 300w, http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.42.59-PM-768x407.png 768w, http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.42.59-PM-788x418.png 788w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/noscript><\/a><\/figure>\n\n\n\n<h2>Getting everything working<\/h2>\n\n\n\n<p>components\/TodoList.vue<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n  &lt;div class=\"hello\"&gt;\n    &lt;section class=\"vh-100\" style=\"background-color: #eee\"&gt;\n      &lt;div class=\"container py-5 h-100\"&gt;\n        &lt;div class=\"row d-flex justify-content-center align-items-center h-100\"&gt;\n          &lt;div class=\"col col-lg-9 col-xl-7\"&gt;\n            &lt;div class=\"card rounded-3\"&gt;\n              &lt;div class=\"card-body p-4\"&gt;\n                &lt;h4 class=\"text-center my-3 pb-3\"&gt;\n                  Simple Vue 2 with composition-api To Do App\n                &lt;\/h4&gt;\n\n                &lt;form\n                  class=\"row row-cols-lg-auto g-3 justify-content-center align-items-center mb-4 pb-2\"\n                  @submit.prevent=\"addToDo\"\n                &gt;\n                  &lt;div class=\"col-12\"&gt;\n                    &lt;div class=\"form-outline\"&gt;\n                      &lt;input\n                        type=\"text\"\n                        id=\"form1\"\n                        v-model=\"state.newTodo\"\n                        class=\"form-control\"\n                        placeholder=\"Enter a task here\"\n                      \/&gt;\n                    &lt;\/div&gt;\n                  &lt;\/div&gt;\n\n                  &lt;div class=\"col-12\"&gt;\n                    &lt;button\n                      type=\"button\"\n                      class=\"btn btn-primary\"\n                      @click=\"addToDo\"\n                    &gt;\n                      Save\n                    &lt;\/button&gt;\n                  &lt;\/div&gt;\n\n                  &lt;div class=\"col-12\"&gt;\n                    &lt;button type=\"submit\" class=\"btn btn-warning\"&gt;\n                      Get tasks\n                    &lt;\/button&gt;\n                  &lt;\/div&gt;\n                &lt;\/form&gt;\n\n                &lt;table class=\"table mb-4\"&gt;\n                  &lt;thead&gt;\n                    &lt;tr&gt;\n                      &lt;th scope=\"col\"&gt;No.&lt;\/th&gt;\n                      &lt;th scope=\"col\"&gt;Todo item&lt;\/th&gt;\n                      &lt;th scope=\"col\"&gt;Status&lt;\/th&gt;\n                      &lt;th scope=\"col\"&gt;Actions&lt;\/th&gt;\n                    &lt;\/tr&gt;\n                  &lt;\/thead&gt;\n\n                  &lt;tbody&gt;\n                    &lt;tr\n                      v-for=\"(todo, idx) in state.todos\"\n                      :key=\"todo.id\"\n                      :class=\"todo.completed &amp;&amp; 'stricked'\"\n                    &gt;\n                      &lt;th scope=\"row\"&gt;{{ idx + 1 }}&lt;\/th&gt;\n                      &lt;td&gt;{{ todo.title }}&lt;\/td&gt;\n                      &lt;td&gt;\n                        {{ todo.completed ? \"Completed\" : \"In progress\" }}\n                      &lt;\/td&gt;\n                      &lt;td&gt;\n                        &lt;button\n                          type=\"submit\"\n                          class=\"btn btn-danger\"\n                          @click=\"removeItem(todo)\"\n                        &gt;\n                          Delete\n                        &lt;\/button&gt;\n                        &lt;button\n                          type=\"submit\"\n                          class=\"btn btn-success ms-1\"\n                          @click=\"toggleCompleted(todo)\"\n                        &gt;\n                          {{ todo.completed ? \"Re-open\" : \"Complete\" }}\n                        &lt;\/button&gt;\n                      &lt;\/td&gt;\n                    &lt;\/tr&gt;\n                  &lt;\/tbody&gt;\n                &lt;\/table&gt;\n              &lt;\/div&gt;\n            &lt;\/div&gt;\n          &lt;\/div&gt;\n        &lt;\/div&gt;\n      &lt;\/div&gt;\n    &lt;\/section&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nimport useTodoList from \"@\/composable\/useTodoList\";\nexport default {\n  setup() {\n    const { state, addToDo, toggleCompleted, removeItem } = useTodoList();\n    return {\n      state,\n      addToDo,\n      toggleCompleted,\n      removeItem,\n    };\n  },\n};\n&lt;\/script&gt;\n\n&lt;!-- Add \"scoped\" attribute to limit CSS to this component only --&gt;\n&lt;style scoped&gt;\nh3 {\n  margin: 40px 0 0;\n}\nul {\n  list-style-type: none;\n  padding: 0;\n}\nli {\n  display: inline-block;\n  margin: 0 10px;\n}\na {\n  color: #37dd92;\n}\n.stricked {\n  text-decoration: line-through;\n}\n&lt;\/style&gt;\n<\/code><\/pre>\n\n\n\n<p>composable\/useTodoList.js<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { reactive } from \"@vue\/composition-api\";\nfunction useTodoList() {\n  let state = reactive({\n    newTodo: \"\",\n    todos: &#91;\n      {\n        id: 1,\n        title: \"Buy groceries for next week\",\n        completed: false,\n      },\n      {\n        id: 2,\n        title: \"Pay credit card bill \",\n        completed: false,\n      },\n    ],\n  });\n\n  function addToDo(e) {\n    console.log(\"state.newTodo\", state, state.newTodo);\n    e.preventDefault();\n    state.todos.push({\n      id: state.todos.length + 1,\n      title: state.newTodo,\n      completed: false,\n    });\n    state.newTodo = \"\";\n  }\n\n  function toggleCompleted(item) {\n    item.completed = !item.completed;\n  }\n  function removeItem(item) {\n    state.todos = state.todos.filter((newItem) =&gt; newItem.id !== item.id);\n  }\n  return {\n    state,\n    addToDo,\n    toggleCompleted,\n    removeItem,\n  };\n}\n\nexport default useTodoList<\/code><\/pre>\n\n\n\n<p>That&#8217;s it Yey !!!<\/p>\n\n\n\n<p>Repo: <a href=\"https:\/\/github.com\/shabeeb\/vue-composition-api-simple-todo\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/shabeeb\/vue-composition-api-simple-todo<\/a><\/p>\n\n\n\n<p>Demo: <a href=\"https:\/\/vue-composition-api-simple-todo.pages.dev\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/vue-composition-api-simple-todo.pages.dev\/<\/a><\/p>\n\n\n\n<p>Thank you for reading and Happy coding \ud83d\ude42<\/p>\n<div class=\"pvc_clear\"><\/div><p class=\"pvc_stats all \" data-element-id=\"629\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;2,334&nbsp;total views, &nbsp;1&nbsp;views today<\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>In this, I&#8217;ll show you how to vue2 composition API. Let us do a small example todo app with Vue composition APIVue 3 come up with Composition API, in Vue 2, we use The Options API, where we use uses&nbsp;options&nbsp;like&nbsp;data,&nbsp;methods, and&nbsp;mounted. With the Composition API, we have a&nbsp;setup&nbsp;hook in which we write our reactive code [&hellip;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"629\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;2,334&nbsp;total views, &nbsp;1&nbsp;views today<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[1,62,63],"tags":[71,76,72,75,64,74],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.4.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Vue\u00a0composition API tutorial with example - shabeeb Blog<\/title>\n<meta name=\"description\" content=\"Simple\u00a0Vue\u00a0application with composition api example. use composition api in existing vue application ref, reactive, watchers, lifecycle hooks\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Vue\u00a0composition API tutorial with example - shabeeb Blog\" \/>\n<meta property=\"og:description\" content=\"A simple\u00a0Vue\u00a0application with composition api todo app example\" \/>\n<meta property=\"og:url\" content=\"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/\" \/>\n<meta property=\"og:site_name\" content=\"shabeeb Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-29T12:27:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-02T10:44:41+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM.png\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"shabeeb\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/shabeebk.com\/blog\/#website\",\"url\":\"http:\/\/shabeebk.com\/blog\/\",\"name\":\"shabeeb Blog\",\"description\":\"A developer blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/shabeebk.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM.png\",\"contentUrl\":\"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM.png\",\"width\":1024,\"height\":530},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/#webpage\",\"url\":\"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/\",\"name\":\"Vue\u00a0composition API tutorial with example - shabeeb Blog\",\"isPartOf\":{\"@id\":\"http:\/\/shabeebk.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/#primaryimage\"},\"datePublished\":\"2022-03-29T12:27:08+00:00\",\"dateModified\":\"2022-04-02T10:44:41+00:00\",\"author\":{\"@id\":\"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/71832abe654179971635c65c09bceb29\"},\"description\":\"Simple\u00a0Vue\u00a0application with composition api example. use composition api in existing vue application ref, reactive, watchers, lifecycle hooks\",\"breadcrumb\":{\"@id\":\"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/shabeebk.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Vue\u00a0composition API tutorial with example\"}]},{\"@type\":\"Person\",\"@id\":\"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/71832abe654179971635c65c09bceb29\",\"name\":\"shabeeb\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"http:\/\/shabeebk.com\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/0.gravatar.com\/avatar\/9998389cc76a77663881c48f7d4cbba0?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/0.gravatar.com\/avatar\/9998389cc76a77663881c48f7d4cbba0?s=96&d=mm&r=g\",\"caption\":\"shabeeb\"},\"description\":\"Developer,Entrepreneur, software engineer more than that a human being\",\"sameAs\":[\"http:\/\/shabeebk.com\/blog\"],\"url\":\"http:\/\/shabeebk.com\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Vue\u00a0composition API tutorial with example - shabeeb Blog","description":"Simple\u00a0Vue\u00a0application with composition api example. use composition api in existing vue application ref, reactive, watchers, lifecycle hooks","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/","og_locale":"en_US","og_type":"article","og_title":"Vue\u00a0composition API tutorial with example - shabeeb Blog","og_description":"A simple\u00a0Vue\u00a0application with composition api todo app example","og_url":"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/","og_site_name":"shabeeb Blog","article_published_time":"2022-03-29T12:27:08+00:00","article_modified_time":"2022-04-02T10:44:41+00:00","og_image":[{"url":"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM.png"}],"twitter_misc":{"Written by":"shabeeb","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"http:\/\/shabeebk.com\/blog\/#website","url":"http:\/\/shabeebk.com\/blog\/","name":"shabeeb Blog","description":"A developer blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/shabeebk.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/#primaryimage","inLanguage":"en-US","url":"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM.png","contentUrl":"http:\/\/shabeebk.com\/blog\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-29-at-5.31.33-PM.png","width":1024,"height":530},{"@type":"WebPage","@id":"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/#webpage","url":"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/","name":"Vue\u00a0composition API tutorial with example - shabeeb Blog","isPartOf":{"@id":"http:\/\/shabeebk.com\/blog\/#website"},"primaryImageOfPage":{"@id":"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/#primaryimage"},"datePublished":"2022-03-29T12:27:08+00:00","dateModified":"2022-04-02T10:44:41+00:00","author":{"@id":"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/71832abe654179971635c65c09bceb29"},"description":"Simple\u00a0Vue\u00a0application with composition api example. use composition api in existing vue application ref, reactive, watchers, lifecycle hooks","breadcrumb":{"@id":"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/shabeebk.com\/blog\/simple-vue-composition-api-example-with-todo-app\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/shabeebk.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Vue\u00a0composition API tutorial with example"}]},{"@type":"Person","@id":"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/71832abe654179971635c65c09bceb29","name":"shabeeb","image":{"@type":"ImageObject","@id":"http:\/\/shabeebk.com\/blog\/#personlogo","inLanguage":"en-US","url":"http:\/\/0.gravatar.com\/avatar\/9998389cc76a77663881c48f7d4cbba0?s=96&d=mm&r=g","contentUrl":"http:\/\/0.gravatar.com\/avatar\/9998389cc76a77663881c48f7d4cbba0?s=96&d=mm&r=g","caption":"shabeeb"},"description":"Developer,Entrepreneur, software engineer more than that a human being","sameAs":["http:\/\/shabeebk.com\/blog"],"url":"http:\/\/shabeebk.com\/blog\/author\/admin\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts\/629"}],"collection":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/comments?post=629"}],"version-history":[{"count":15,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts\/629\/revisions"}],"predecessor-version":[{"id":721,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts\/629\/revisions\/721"}],"wp:attachment":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/media?parent=629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/categories?post=629"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/tags?post=629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}