Comments (13)
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.
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.
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.
But
console.log(Vue['__composition_api_installed__']);
seems to print false, so maybe it's not the case
from vue-demi.
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.
Yes. From v0.3.x, @vue/composition-api
becomes a peerDependency which you should install it manually.
from vue-demi.
And I think you should use
import { defineComponent } from "vue-demi"
instead of
import Vue from "vue-demi"
from vue-demi.
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.
@Devoter What is the bundler you are using? Can you share a reproduce repo? Thanks.
from vue-demi.
@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.
Minimal repro: https://github.com/MartinMalinda/vue-tiny-emitter
from vue-demi.
@MartinMalinda Sorry for the delay but I just pull done your repo and it seems to work for me
from vue-demi.
@MartinMalinda Sorry for the delay but I just pull done your repo and it seems to work for me
I have to confirm, everything works fine with the lastest version. I don't know why.
from vue-demi.
Related Issues (20)
- Remove peerDependencies
- Can't use Vue 2 library in Vue 3 HOT 1
- The requested module 'vue-demi' does not provide an export named 'computed' HOT 3
- Packaged a custom hook with rollup, ref did not unpack it automatically in the template HOT 2
- vue3.3 + ts, when v-for the computed array, the item type reference error
- Uses the wrong vue version in monorepo HOT 5
- How we resolve dependency issue for ? HOT 1
- v0.14.5 recently overwritten? and v0.14.6 does not work... HOT 11
- vue-demi-fix is missing HOT 5
- 这个文件前边都是es5语法,最后加的这一行箭头函数让我们构建时不得不对vue-demi单独加一条适配规则 HOT 1
- `postinstall` script doesn't play well with `pnpm` on Windows HOT 8
- vue.use 和 vue.default.use问题导致报错 HOT 1
- [HELP] The requested module '/node_modules/.vite/deps/vue.js?v=3af26c34' does not provide an export named 'Fragment'
- Reactivity loss when using with @vue/compat HOT 1
- TypeScript got incorrect vue version with pnpm workspace HOT 1
- Refactor with typescript ?
- Bun install segfault in Docker
- 安装依赖携带 --ignore-scripts 会导致无法在vue2的项目中使用
- scoped not support vue@2
- Build Error Resolved by Downgrading Vue-Demi from 0.14.9 to 0.14.5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-demi.