vuejs / composition-api

Composition API plugin for Vue 2
https://composition-api.vuejs.org/
MIT License
4.19k stars 342 forks source link

Doesn't work with nuxt-typescript #227

Closed avxkim closed 4 years ago

avxkim commented 4 years ago

Created nuxt app using npx create-nuxt-app. Followed documentation at https://typescript.nuxtjs.org, however i have an issue using @vue/composition-api:

example component.vue:

<template>
  <div>
    {{ msg }}
  </div>
</template>

<script lang="ts">
import { createComponent, ref } from '@vue/composition-api'

export default createComponent({
  setup() {
    const msg = ref('hello')

    return {
      msg
    }
  }
})
</script>

Doesn't work, throws an error "Property or method "msg" is not defined on the instance but referenced during render." because it doesn't see my ref. I've added composition API as plugin in "plugins/composition-api.ts":

import Vue from 'vue'
import VueCompositionApi from '@vue/composition-api'

Vue.use(VueCompositionApi)

Then in nuxt.config.ts:

plugins: ['@/plugins/composition-api']

posva commented 4 years ago

Make sure you are also running nuxt with nuxt-ts and that you don't have an extra config file that may interfere (like nuxt.config.js). I recreated a project and it's running fine. This question should be asked in the forum or chat instead, I'm sure you will find some help and fix the local issue you are facing

SampsonM commented 4 years ago

I'm getting the same error, following the guide shown here I get the error "Cannot find module '@vue/composition-api' from '/srv'" when running in debug mode.

@webcoderkz did you manage to figure this one out?

LouisMazel commented 4 years ago

See these issues : 1 - https://github.com/nuxt-community/composition-api/issues/241 ([vue-composition-api] already installed. Vue.use(VueCompositionAPI) should be called only once) 2 - https://github.com/nuxt-community/composition-api/issues/290 (Cannot find module '@vue/composition-api')