Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

basic vue-lodash usage - errors inside component

See original GitHub issue

I’m doing sth wrong, but following your instructions, I installed globally vue lodash

import Vue from 'vue'
import lodash from 'lodash'
import VueLodash from 'vue-lodash'

Vue.use(VueLodash, lodash)

now using computed in one of my component:

debounceText: {
        get() { return this.proTemplateAdd; },
        set: this._.debounce(function(newValue) {
          this.proTemplateAdd = newValue;
        }, 100)

I’ve got: Uncaught TypeError: Cannot read property 'debounce' of undefined

using Vue._.debounce(function(newValue)

I’ve got: Uncaught ReferenceError: Vue is not defined

I’m beginner in Vue, so I will be happy to see what I’m doing wrong. Now I’m using just import _ from 'lodash' in my component and it works fine…

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

Ewockercommented, Mar 23, 2018

@gileneusz Sorry, you won’t need reproduction, I should have spot your problem earlier (wasn’t looking to close). 😃 For your above example, it seems like the problem is not related to vue-lodash. The reference here of this is not in the scope, notice that for any vuejs syntax for methods or function, keyword this will only be able to reference inside the created function; however here, you are creating a function and passing its reference where this is not defined. In other words, if you have

methods: {
    random: this._.random(20) // 'this' is not defined
    randomWorking () {
         this._.random(20) // here this == Vue

For you learning, you can try create a test method that does the following: (Note that the first one needs to be commented out if you want the second one to work.)

    test () {

For the second thing using the Vue._.XXXX methods. The reason of Vue is not defined error shows up is that you do not import the Vue object with:

import Vue from 'vue'

!!! In the component that you are testing.

Even if you did that in main.js or index.js, you are not able to reference it here, consider other plugins like axios, unless you use global axios plugin such as vue-axios, it has to be imported in each of the component.

kwojtcommented, Mar 24, 2018

Oh my, I just saw what I did. I tried to use this._.isUndefined() not directly in Vue component, but in additionall class, which I was using in it 😛 So basic mistake…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vuejs can't use lodash inside template but it works on code
I could refactor creating a new variable and assign the value in code and it will work, but I want to use it...
Read more >
Not able to use lodash or jquery inside interpolations in .vue ...
When I try to use any lodash function inside an interpolation I get the following error in the console: [Vue warn]: Property or...
Read more >
Vue Error Handling - Mastering JS
Vue instances have a neat `errorCaptured` function that Vue calls whenever an error occurs in a method or lifecycle hook.
Read more >
How to use Lodash with Vue |
The typical way to start using Lodash in your Vue application is to import the needed function on a Vue component basis. And...
Read more >
Reactivity Fundamentals - Vue.js
With Options API, we use the data option to declare reactive state of a component. The option value should be a function that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found