Git Product home page Git Product logo

Comments (13)

MartinMalinda avatar MartinMalinda commented on May 25, 2024

Huh, there is a Vue exported, so I'm trying:

import Vue from "vue";
import CompositionApi from "@vue/composition-api";
import { Vue as VueDemiVue } from 'vue-demi';

Vue.use(CompositionApi);
VueDemiVue.use(CompositionApi);

But I get:

TypeError: Cannot read property 'use' of undefined

from vue-demi.

antfu avatar antfu commented on May 25, 2024

Thanks, I will have a look on that.

And you don't have to install VCA I think. vue-demi should already do that for you.

Meanwhile, If you want to install other plugins, the best way to do might be:

import { createApp } from 'vue-demi'

const app = createApp()
app.use(xxxx)

as Vue.use is no longer there in Vue 3. app.use in Vue 2 is a polyfill by VCA plugin and it's equivalent to Vue.use.

from vue-demi.

MartinMalinda avatar MartinMalinda commented on May 25, 2024

I'm doing now import Vue from "vue-demi"; in tests

Then I'm creating a wrapper component in which I want to test the utility functions

export function createComponentStub(
  name: string,
  setup = (props, context) => { }
) {
  const stubAttr = `data-test-${name}-stub`;
  return Vue.defineComponent({
    name,
    setup,
    render(el) {
      return el("div", {
        attrs: {
          [stubAttr]: true,
        },
      });
    },
  });
}

When I render this component I pass localVue from vue-demi:

 render(component, {
    localVue: Vue as any
  });

Still it seems that setup() does not get called, which is strange because the imported Vue AFAIK should have the compositionAPI plugin added:

https://github.com/antfu/vue-demi/blob/master/lib/v2/index.esm.js#L5

from vue-demi.

MartinMalinda avatar MartinMalinda commented on May 25, 2024

But

console.log(Vue['__composition_api_installed__']); seems to print false, so maybe it's not the case

from vue-demi.

MartinMalinda avatar MartinMalinda commented on May 25, 2024

If I uninstall VCA completely I'm getting:

Test suite failed to run

    Cannot find module '@vue/composition-api' from 'node_modules/vue-demi/
lib/v2/index.cjs.js'

    Require stack:
      node_modules/vue-demi/lib/v2/index.cjs.js
      node_modules/vue-demi/lib/index.cjs.js
      test-utils/vue-setup.ts

from vue-demi.

antfu avatar antfu commented on May 25, 2024

Yes. From v0.3.x, @vue/composition-api becomes a peerDependency which you should install it manually.

from vue-demi.

antfu avatar antfu commented on May 25, 2024

And I think you should use

import { defineComponent } from "vue-demi"

instead of

import Vue from "vue-demi"

from vue-demi.

Devoter avatar Devoter commented on May 25, 2024

But

console.log(Vue['__composition_api_installed__']); seems to print false, so maybe it's not the case

Yes, that looks strange:

import VueCompositionApi from '@vue/composition-api';
import { Vue, isVue2, createApp, defineComponent } from 'vue-demi';

import { tracked, calculated } from '.';

if (isVue2) {
  console.log('Vue 2', ((Vue as unknown) as Record<string, unknown>)['__composition_api_installed__']); // Vue 2 undefined ?!
  Vue.use(VueCompositionApi);
  console.log('Vue 2', ((Vue as unknown) as Record<string, unknown>)['__composition_api_installed__']); // Vue 2 true
}

from vue-demi.

antfu avatar antfu commented on May 25, 2024

@Devoter What is the bundler you are using? Can you share a reproduce repo? Thanks.

from vue-demi.

Devoter avatar Devoter commented on May 25, 2024

@antfu Sorry, I cannot share a repo for now. I use bili for building and ts-jest for testing. I'll try to prepare it for you later.

from vue-demi.

MartinMalinda avatar MartinMalinda commented on May 25, 2024

Minimal repro: https://github.com/MartinMalinda/vue-tiny-emitter

from vue-demi.

antfu avatar antfu commented on May 25, 2024

@MartinMalinda Sorry for the delay but I just pull done your repo and it seems to work for me

image

from vue-demi.

Devoter avatar Devoter commented on May 25, 2024

@MartinMalinda Sorry for the delay but I just pull done your repo and it seems to work for me

image

I have to confirm, everything works fine with the lastest version. I don't know why.

from vue-demi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.