basic vue-lodash usage - errors inside component
See original GitHub issueI’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:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top 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 | SamanthaMing.com
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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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
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.)
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:
!!! 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.
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…