Home > Blockchain >  Vue 3 use function not works
Vue 3 use function not works

Time:04-21

I tried to upgrade one of my apps from Vue 2 to Vue 3. Unfortunately I can't use: Vue.use() function. For example my code in Vue 2:

import Vue from 'vue'
import App from './App.vue'
import store from './store'
import router from './router'
import VueCookie from 'vue-cookie'

Vue.use(VueCookie);


new Vue({
    store,
    router,
    render: h => h(App)
}).$mount('#app')

Same in Vue 3:

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { store } from './store'
import VueCookie from 'vue-cookie'

//Vue.use(VueCookie); //old line in vue 2
createApp.use('VueCookie'); //this is not works and return error

createApp(App).use(router,store).mount('#app') //Is this line correct?

What am I missing here?

CodePudding user response:

Try like following, first define app then use it:

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import VueCookie from 'vue-cookie'

const app = createApp(App);

app.use(router);
app.use(store);
app.use(VueCookie);
app.mount('#app')

CodePudding user response:

You can use it like:

  import VueCookie from 'vue-cookie'

  VueCookie.set("mycookie", "value", "1h")
  • Related