{"id":26848,"date":"2023-08-08T08:27:10","date_gmt":"2023-08-08T06:27:10","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=26848"},"modified":"2023-08-08T08:27:12","modified_gmt":"2023-08-08T06:27:12","slug":"setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/","title":{"rendered":"Setting up Your First Pinia Store in Vue with TypeScript &#8211; A Comprehensive Guide"},"content":{"rendered":"\n<p>Welcome to this blog, we\u2019re going to setup our first Pinia store in a Vue application with typescript support.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-first-what-is-pinia\">First, what is Pinia ?<\/h2>\n\n\n\n<p>From Pinia official website, <em>&#8220;Pinia is a store library for Vue, it allows you to share a state across components\/pages. A pineapple is in reality a group of individual flowers that join together to create a multiple fruit. Similar to stores, each one is born individually, but they are all connected at the end.&#8221;<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why using Pinia instead of Vuex ?<\/h2>\n\n\n\n<p>First of all, Pinia is now the state management tool officially recommended in Vue documentation. It has been mentioned as the version 5 of Vuex.<br>With Pinia, you can forget about mutations, no need to worry about its complex verbosity. It fully supports TypeScript and provides autocompletion even in JavaScript. It\u2019s also light, modular and extensible.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating our Vue app<\/h2>\n\n\n\n<p>Just before creating the app, notice that I\u2019m using Vue cli version 5.0.8 and npm version 9.5.1.<br>That said, we can start with the app creation.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"542\" height=\"382\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image001.png\" alt=\"\" class=\"wp-image-26852\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image001.png 542w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image001-300x211.png 300w\" sizes=\"auto, (max-width: 542px) 100vw, 542px\" \/><\/figure>\n\n\n\n<p>As you can notice, we directly have the possibility to Add Pinia to our new project. We also choose to enable TypeScript, Vue Router, ESLint and Prettier.<\/p>\n\n\n\n<p>Then, follow the step indicated by the Vue cli:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd pinia-blog\nnpm install\n<\/code><\/pre>\n\n\n\n<p>Your project is now ready to start and afterwards you can open it the browser.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm run dev<\/code><\/pre>\n\n\n\n<p>If you press \u201co\u201d from the Vue cli, it\u2019ll open a new window in your browser.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"534\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image002-1024x534.png\" alt=\"\" class=\"wp-image-26858\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image002-1024x534.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image002-300x157.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image002-768x401.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image002.png 1292w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Cleaning automatically generated code<\/h2>\n\n\n\n<p>By default, many files are generated in the project, we don&#8217;t need it for our app and we can therefore clean it.<br>Before deleting the files, stop your server from the terminal with \u201cctrl+c\u201d or you will get some errors because of the missing files.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"238\" height=\"549\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image003.png\" alt=\"\" class=\"wp-image-26861\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image003.png 238w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image003-130x300.png 130w\" sizes=\"auto, (max-width: 238px) 100vw, 238px\" \/><\/figure>\n\n\n\n<p>You can also delete AboutView.vue in views folder.<\/p>\n\n\n\n<p>Next, clean the following files:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>router\/index.ts:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>import { createRouter, createWebHistory } from 'vue-router'\nimport HomeView from '..\/views\/HomeView.vue'\n\nconst router = createRouter({\n  history: createWebHistory(import.meta.env.BASE_URL),\n  routes: &#091;\n    {\n      path: '\/',\n      name: 'home',\n      component: HomeView\n    },\n  ]\n})\n\nexport default router\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>App.vue:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script setup lang=\"ts\"&gt;\nimport { RouterView } from 'vue-router'\n&lt;\/script&gt;\n\n&lt;template&gt;\n  &lt;RouterView \/&gt;\n&lt;\/template&gt;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>HomeView.vue:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script setup lang=\"ts\"&gt;\n&lt;\/script&gt;\n\n&lt;template&gt;\n  &lt;main&gt;\n  &lt;\/main&gt;\n&lt;\/template&gt;\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Generated Store<\/h2>\n\n\n\n<p>As we added Pinia when creating our Vue project, it has updated our main.ts file to use Pinia and generated an example store in <strong>src\/stores<\/strong>.<br>For this blog, we\u2019ll use this example, let\u2019s have a look at it.<\/p>\n\n\n\n<p>main.ts:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import '.\/assets\/main.css'\n\nimport { createApp } from 'vue'\nimport { createPinia } from 'pinia'\n\nimport App from '.\/App.vue'\nimport router from '.\/router'\n\nconst app = createApp(App)\n\napp.use(createPinia())\napp.use(router)\n\napp.mount('#app')\n<\/code><\/pre>\n\n\n\n<p>In the import statements, you can see the function createPinia.<br>It\u2019s used few lines later to create the Pinia root store and then it\u2019s passed to the app.<\/p>\n\n\n\n<p>Concerning the Store file, let\u2019s have a look in detail:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { ref, computed } from 'vue'\nimport { defineStore } from 'pinia'\n\nexport const useCounterStore = defineStore('counter', () =&gt; {\n  const count = ref(0)\n  const doubleCount = computed(() =&gt; count.value * 2)\n  function increment() {\n    count.value++\n  }\n\n  return { count, doubleCount, increment }\n})<\/code><\/pre>\n\n\n\n<p>The first thing to notice is that the store is written as a Setup Store. Setup Store is a syntax to define stores. It\u2019s similar to the Vue Composition API\u2019s setup function. You can also write store file as Option Stores, similar to Vue\u2019s options API.<br>From Vue documentation, \u201c<em>Setup stores bring a lot more flexibility than Option Stores as you can create watchers within a store and freely use any composable. However, keep in mind that using composables will get more complex when using SSR.<\/em><br>S<em>etup stores are also able to rely on globally provided properties like the Router or the Route. Any property provided at the App level can be accessed from the store using inject()\u201d<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>import { ref, computed } from 'vue'<\/code><\/code><\/pre>\n\n\n\n<p>This line imports the <code>ref<\/code> and <code>computed<\/code> functions from the Vue library. <code>ref<\/code> is used to create reactive references to values, and <code>computed<\/code> is used to create computed properties that automatically update when their dependencies change.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>import { defineStore } from 'pinia'<\/code><\/code><\/pre>\n\n\n\n<p>This line imports the <code>defineStore<\/code> function from the Pinia library, used to define a store.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>export const useCounterStore = defineStore('counter', () =&gt; {<\/code><\/code><\/pre>\n\n\n\n<p>This line exports a Pinia store called <code>useCounterStore<\/code>. The <code>defineStore<\/code> function is used to create a Pinia store and takes two arguments: a unique name for the store (in this case, <code>'counter'<\/code>), and a setup function that initializes the store&#8217;s state and methods.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>const count = ref(0)<\/code><\/code><\/pre>\n\n\n\n<p>This line creates a reactive reference (<code>ref<\/code>) named <code>count<\/code> and initializes it with the value <code>0<\/code>. This will be our state variable representing the count in the counter store.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>const doubleCount = computed(() =&gt; count.value * 2)<\/code><\/code><\/pre>\n\n\n\n<p>This line creates a computed property named <code>doubleCount<\/code> using the <code>computed<\/code> function. It calculates the double value of <code>count<\/code> by multiplying <code>count.value<\/code> by 2. The <code>computed<\/code> property will automatically update whenever <code>count<\/code> changes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>function increment() { count.value++ }<\/code><\/code><\/pre>\n\n\n\n<p>This line defines a function named <code>increment<\/code> that increments the value of <code>count<\/code> by one. Since <code>count<\/code> is a reactive reference, updating its value with <code>count.value++<\/code> will automatically trigger reactivity and update any dependent computed properties.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>return { count, doubleCount, increment }<\/code><\/code><\/pre>\n\n\n\n<p>This line returns an object containing the <code>count<\/code>, <code>doubleCount<\/code>, and <code>increment<\/code> properties. These properties represent the state (count), the computed property (doubleCount), and the method (increment) of the Pinia store. They will be accessible to components that use this store via the <code>useCounterStore<\/code> store instance.<\/p>\n\n\n\n<p>Time to use our store !<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Store usage<\/h2>\n\n\n\n<p>Usually you should create a component that you\u2019d call in a view file, but here, as the goal is to understand how to use Pinia, we\u2019ll simply use HomeView.vue.<br>We\u2019ll edit the file, simply to use the count, doubleCount and increment properties:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n  &lt;div&gt;\n    &lt;h1&gt;Home View&lt;\/h1&gt;\n    &lt;p&gt;Count: {{ counter.count }}&lt;\/p&gt;\n    &lt;p&gt;Double Count: {{ counter.doubleCount }}&lt;\/p&gt;\n    &lt;button @click=\"counter.increment()\"&gt;Increment&lt;\/button&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script lang=\"ts\" setup&gt;\nimport { useCounterStore } from '@\/stores\/counter'\n\nconst counter = useCounterStore()\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p>Let\u2019s have a deep dive to understand what\u2019s going on in there:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script lang=\"ts\" setup&gt;<\/code><\/pre>\n\n\n\n<p>The script section of the file is declared with setup attribute. It enables the new setup syntax in Vue 3, which simplifies the way we define data, computed properties, and methods.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { useCounterStore } from '@\/stores\/counter'<\/code><\/pre>\n\n\n\n<p>In the script section, we first import the useCounterStore function from our store file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const counter = useCounterStore()<\/code><\/pre>\n\n\n\n<p>This line calls the useCounterStore function to create an instance of the counter store and stores it in the counter variable (Remember that our function useCounterStore() returns an object). This instance will be reactive, meaning any changes to the state or computed properties in the store will automatically trigger updates in the template where counter is used.<\/p>\n\n\n\n<p>Looking at the template section now, it contains the HTML structure that defines the visual representation of the component.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;p&gt;Count: {{ counter.count }}&lt;\/p&gt;\n&lt;p&gt;Double Count: {{ counter.doubleCount }}&lt;\/p&gt;\n&lt;button @click=\"counter.increment()\"&gt;Increment&lt;\/button&gt;<\/code><\/pre>\n\n\n\n<p>It contains two paragraphs (&lt;p&gt;) that display the count and doubleCount properties from the counter object, respectively. There is also a button that calls the increment method when clicked.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Test the application<\/h2>\n\n\n\n<p>You can now test the application by running the \u201cnpm run dev\u201d command in your terminal and then open it in the browser with \u201co\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"752\" height=\"160\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image004.png\" alt=\"\" class=\"wp-image-26880\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image004.png 752w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image004-300x64.png 300w\" sizes=\"auto, (max-width: 752px) 100vw, 752px\" \/><\/figure>\n\n\n\n<p>Click on the increment button, you should directly see the updated values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sharing the data across multiple component<\/h2>\n\n\n\n<p>The advantage of using a state management tool like Pinia, is that the state of your store can be shared across your whole application. Let\u2019s verify it.<\/p>\n\n\n\n<p>Create a new view File named CounterView.ts in your views folder.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n  &lt;div&gt;\n    &lt;h1&gt;Counter View&lt;\/h1&gt;\n    &lt;p&gt;Count: {{ counter.count }}&lt;\/p&gt;\n    &lt;p&gt;Double Count: {{ counter.doubleCount }}&lt;\/p&gt;\n    &lt;button @click=\"counter.increment()\"&gt;Increment&lt;\/button&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script lang=\"ts\" setup&gt;\nimport { useCounterStore } from '@\/stores\/counter'\n\nconst counter = useCounterStore()\n&lt;\/script&gt;\n<\/code><\/pre>\n\n\n\n<p>Update the router file router\/index.ts so that you can access your new file through routing.<\/p>\n\n\n\n<p>Import your new view file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import CounterView from '..\/views\/CounterView.vue'<\/code><\/pre>\n\n\n\n<p>Add the following object into the routes array:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    {\n      path: '\/counter',\n      name: 'counter',\n      component: CounterView\n    },<\/code><\/pre>\n\n\n\n<p>Add a link into the template section of each view file to navigate between them:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>HomeView.vue:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- Router link to go to \"\/counter\" --&gt;\n&lt;router-link to=\"\/counter\"&gt;Go to Counter&lt;\/router-link&gt;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>CounterView.vue:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- Router link to go to \"\/\" --&gt;\n&lt;router-link to=\"\/\"&gt;Go to Home&lt;\/router-link&gt;<\/code><\/pre>\n\n\n\n<p>Now, if you click on the increment button and then click on the link to go to the counter page, you can see that the value of the counter property has also been updated there.<br>This is thanks to the state of the count property that is managed in Pinia.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bonus<\/h2>\n\n\n\n<p>To help you debug your Vue application and also to understand what is going on in your Pinia stores, I recommend you to install the Vue dev tools.<br>It\u2019s a browser extension available from the dev panel.<br>For example, within our application it\u2019s useful to control the properties of our stores:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"762\" height=\"429\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image005.png\" alt=\"\" class=\"wp-image-26881\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image005.png 762w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image005-300x169.png 300w\" sizes=\"auto, (max-width: 762px) 100vw, 762px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p>In conclusion, we&#8217;ve embarked on a journey to set up our first Pinia store in a Vue application with TypeScript support. Through this blog, we&#8217;ve explored the key concepts of Pinia.<\/p>\n\n\n\n<p>Thank you for joining me on this exploration of Pinia and Vue. With your newfound understanding, you&#8217;re now ready to create robust, reactive, and efficient applications that make the most of the power and simplicity that Pinia offers. Happy coding!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Useful Links<\/h2>\n\n\n\n<p>Pinia official documentation : <a href=\"https:\/\/pinia.vuejs.org\/introduction.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/pinia.vuejs.org\/introduction.html<\/a><\/p>\n\n\n\n<p>Vue official documentation : <a href=\"https:\/\/vuejs.org\/guide\/quick-start.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/vuejs.org\/guide\/quick-start.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to this blog, we\u2019re going to setup our first Pinia store in a Vue application with typescript support. First, what is Pinia ? From Pinia official website, &#8220;Pinia is a store library for Vue, it allows you to share a state across components\/pages. A pineapple is in reality a group of individual flowers that [&hellip;]<\/p>\n","protected":false},"author":87,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3029],"tags":[3030,3032,3042,3033,3034,3035,3031,120],"type_dbi":[3036,3040,3041,3039,3038,3037],"class_list":["post-26848","post","type-post","status-publish","format-standard","hentry","category-web","tag-development","tag-pinia","tag-state","tag-store","tag-vue","tag-vuejs","tag-web","tag-web-application","type-development-web","type-pinia","type-store","type-vue","type-vuejs","type-web"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Setting up Your First Pinia Store in Vue with TypeScript - dbi Blog<\/title>\n<meta name=\"description\" content=\"Learn how to set up and use Pinia, a powerful store library for Vue, in your Vue application with TypeScript support. Discover how to share state across components\/pages. Follow our step-by-step guide to create a Vue app with Pinia, clean the automatically generated code, and use the Pinia store effectively.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Setting up Your First Pinia Store in Vue with TypeScript - A Comprehensive Guide\" \/>\n<meta property=\"og:description\" content=\"Learn how to set up and use Pinia, a powerful store library for Vue, in your Vue application with TypeScript support. Discover how to share state across components\/pages. Follow our step-by-step guide to create a Vue app with Pinia, clean the automatically generated code, and use the Pinia store effectively.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-08T06:27:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-08T06:27:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image001.png\" \/>\n<meta name=\"author\" content=\"Joan Frey\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Joan Frey\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/\"},\"author\":{\"name\":\"Joan Frey\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/c03c47649664fe73b27ce457e99f5b06\"},\"headline\":\"Setting up Your First Pinia Store in Vue with TypeScript &#8211; A Comprehensive Guide\",\"datePublished\":\"2023-08-08T06:27:10+00:00\",\"dateModified\":\"2023-08-08T06:27:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/\"},\"wordCount\":1296,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image001.png\",\"keywords\":[\"development\",\"Pinia\",\"state\",\"store\",\"vue\",\"vuejs\",\"web\",\"Web Application\"],\"articleSection\":[\"Web\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/\",\"name\":\"Setting up Your First Pinia Store in Vue with TypeScript - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image001.png\",\"datePublished\":\"2023-08-08T06:27:10+00:00\",\"dateModified\":\"2023-08-08T06:27:12+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/c03c47649664fe73b27ce457e99f5b06\"},\"description\":\"Learn how to set up and use Pinia, a powerful store library for Vue, in your Vue application with TypeScript support. Discover how to share state across components\/pages. Follow our step-by-step guide to create a Vue app with Pinia, clean the automatically generated code, and use the Pinia store effectively.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#primaryimage\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image001.png\",\"contentUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image001.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Setting up Your First Pinia Store in Vue with TypeScript &#8211; A Comprehensive Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/c03c47649664fe73b27ce457e99f5b06\",\"name\":\"Joan Frey\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/1e650cf665b4d44dd186355827c0b049d2f95c8cbb45fd10d4e7cb255be67ecb?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1e650cf665b4d44dd186355827c0b049d2f95c8cbb45fd10d4e7cb255be67ecb?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1e650cf665b4d44dd186355827c0b049d2f95c8cbb45fd10d4e7cb255be67ecb?s=96&d=mm&r=g\",\"caption\":\"Joan Frey\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/joanfrey\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Setting up Your First Pinia Store in Vue with TypeScript - dbi Blog","description":"Learn how to set up and use Pinia, a powerful store library for Vue, in your Vue application with TypeScript support. Discover how to share state across components\/pages. Follow our step-by-step guide to create a Vue app with Pinia, clean the automatically generated code, and use the Pinia store effectively.","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":"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/","og_locale":"en_US","og_type":"article","og_title":"Setting up Your First Pinia Store in Vue with TypeScript - A Comprehensive Guide","og_description":"Learn how to set up and use Pinia, a powerful store library for Vue, in your Vue application with TypeScript support. Discover how to share state across components\/pages. Follow our step-by-step guide to create a Vue app with Pinia, clean the automatically generated code, and use the Pinia store effectively.","og_url":"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/","og_site_name":"dbi Blog","article_published_time":"2023-08-08T06:27:10+00:00","article_modified_time":"2023-08-08T06:27:12+00:00","og_image":[{"url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image001.png","type":"","width":"","height":""}],"author":"Joan Frey","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Joan Frey","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/"},"author":{"name":"Joan Frey","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/c03c47649664fe73b27ce457e99f5b06"},"headline":"Setting up Your First Pinia Store in Vue with TypeScript &#8211; A Comprehensive Guide","datePublished":"2023-08-08T06:27:10+00:00","dateModified":"2023-08-08T06:27:12+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/"},"wordCount":1296,"commentCount":0,"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image001.png","keywords":["development","Pinia","state","store","vue","vuejs","web","Web Application"],"articleSection":["Web"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/","url":"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/","name":"Setting up Your First Pinia Store in Vue with TypeScript - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image001.png","datePublished":"2023-08-08T06:27:10+00:00","dateModified":"2023-08-08T06:27:12+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/c03c47649664fe73b27ce457e99f5b06"},"description":"Learn how to set up and use Pinia, a powerful store library for Vue, in your Vue application with TypeScript support. Discover how to share state across components\/pages. Follow our step-by-step guide to create a Vue app with Pinia, clean the automatically generated code, and use the Pinia store effectively.","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#primaryimage","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image001.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/07\/image001.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/setting-up-your-first-pinia-store-in-vue-with-typescript-a-comprehensive-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Setting up Your First Pinia Store in Vue with TypeScript &#8211; A Comprehensive Guide"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/c03c47649664fe73b27ce457e99f5b06","name":"Joan Frey","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1e650cf665b4d44dd186355827c0b049d2f95c8cbb45fd10d4e7cb255be67ecb?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1e650cf665b4d44dd186355827c0b049d2f95c8cbb45fd10d4e7cb255be67ecb?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1e650cf665b4d44dd186355827c0b049d2f95c8cbb45fd10d4e7cb255be67ecb?s=96&d=mm&r=g","caption":"Joan Frey"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/joanfrey\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/26848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=26848"}],"version-history":[{"count":30,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/26848\/revisions"}],"predecessor-version":[{"id":27164,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/26848\/revisions\/27164"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=26848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=26848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=26848"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=26848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}