Setup Axios

This plugin gives you useful functions which is extending the Repository

Install Pinia ORM Axios Plugin

Yarn
yarn add @pinia-orm/axios
NPM
npm install @pinia-orm/axios --save
PNPM
pnpm add @pinia-orm/axios

Adding the plugin to your pinia ORM store

You have to options here to use the plugin. Either you use createPiniaOrmAxios(options?: PinaOrmPluginOptions) or you use pinaOrmPluginAxios. It depends if you want to pass options on initialization or later.

Vue3
import { createPinia } from 'pinia'
import { createORM } from 'pinia-orm'
import { createPiniaOrmAxios } from '@pinia-orm/axios'
import axios from 'axios'
const pinia = createPinia()
const piniaOrm = createORM({
  plugins: [
    createPiniaOrmAxios({
      axios,
    }),
  ],
})
pinia.use(piniaOrm)
Vue2
import { createPinia, PiniaVuePlugin } from 'pinia'
import { createORM } from 'pinia-orm'
import { createPiniaOrmAxios } from '@pinia-orm/axios'
import axios form 'axios'
Vue.use(PiniaVuePlugin)
const pinia = createPinia()
const piniaOrm = createORM({
  plugins: [
    createPiniaOrmAxios({
      axios,
    }),
  ],
})
pinia.use(piniaOrm)

Usage with Nuxt

With Nuxt you register the plugin in a Nuxt plugin file, e.g. plugins/pinia-orm-axios.ts. The plugin has to be applied to the pinia instance after the pinia plugin has been set up:

import { defineNuxtPlugin, usePinia } from '#imports'
import { createPiniaOrmAxios } from '@pinia-orm/axios'
import axios from 'axios'
import { setActivePinia } from 'pinia'
import { createORM } from 'pinia-orm'
export default defineNuxtPlugin({
  name: 'pinia-orm-axios',
  dependsOn: ['pinia'],
  setup () {
    const pinia = usePinia()
    pinia.use(createORM({
      plugins: [
        createPiniaOrmAxios({
          axios,
          // baseURL: 'https://example.com/api',
        }),
      ],
    }))
    setActivePinia(pinia)
  },
})
When you register createORM yourself in a plugin like this, you don't need the @pinia-orm/nuxt module — the plugin above replaces it.