Skip to content

Cannot set property '$device' of undefined on Vue 3 #2

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

Open
agustinguerr4 opened this issue Aug 31, 2021 · 1 comment
Open

Cannot set property '$device' of undefined on Vue 3 #2

agustinguerr4 opened this issue Aug 31, 2021 · 1 comment

Comments

@agustinguerr4
Copy link

agustinguerr4 commented Aug 31, 2021

Hi there! I am getting this error when trying to use this plugin in my application (Vue 3).
The error occurs in the .index.js file, where the "device" const is defined.

It finally worked when I replaced (from /node_modules/vue-device-detector/main.js)

const device = {
    install(Vue, options) {
        Vue.prototype.$device = devices()
    }
}
export default device

for this

export default {
    install(app) {
        app.provide('device', devices())
    }
}

Then, in main.js from my app

import Device from 'vue-device-detector-js'
app.use(Device) 

Finally, on the component

import { inject, onMounted } from "vue";

export default {
    setup(){
        const device = inject("device");
        onMounted(() => { 
             console.log(device)
        }
    }
}

if this is a good way, i think that i must close de question, but i'm not sure.

@ovidiublagaai
Copy link

I changed the file in node_modules but it won't save. Can you tell me how you saved it?

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