Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt3 with vue 3 composion API #147

Open
fawel11 opened this issue Mar 30, 2023 · 1 comment
Open

Nuxt3 with vue 3 composion API #147

fawel11 opened this issue Mar 30, 2023 · 1 comment

Comments

@fawel11
Copy link

fawel11 commented Mar 30, 2023

I have been using this pakcage for my vue2 project without nuxt.
But I tried to use it in my nuxt3 project. But I couldn't be able to run the package.

plugin/apiFetch.ts:
`import { defineNuxtPlugin } from '#app'
import Cookies from 'js-cookie'

export default defineNuxtPlugin(nuxtApp => {
const config = useRuntimeConfig()

let token =Cookies.get('TOKEN');//'49|VKVPHxftNkveptKUy9lBP5OQtnqQXWsWOjzFOeym'

const headers = {
Authorization: Bearer ${token},
Accept: 'application/json',
'X-XSRF-TOKEN': Cookies.get('XSRF-TOKEN'),
}
nuxtApp.provide(
'apiFetch',
$fetch.create({
baseURL: config.BASE_URL,
credentials: 'include',
headers: headers,
})
)
})`

How can i use form.post in my component? I used this:

`const { $apiFetch } = useNuxtApp()

  const form = reactive( {
    leave_reason: null,

  } )


  async function apply() {

  
    // const rr = await $apiFetch('/leave/apply-leave', {method: 'POST'})
    const response = await this.form.post('/leave/apply-leave')

//this.form=rr;

  }`

But not worked. Anyone here to help?

@dipuahmed018
Copy link

dipuahmed018 commented Apr 10, 2023

Can you try this?

const form = reactive(new Form({
    leave_reason: null,
  })
 )

and instead of
this.form.post

just use
form.post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants