Answer the question
In order to leave comments, you need to log in
Why do they put Vue.js const vm everywhere instead of this?
Why even in the smallest functions in const vm do they save this?
In what situations is it necessary, and in what situations is it unnecessary?
Answer the question
In order to leave comments, you need to log in
на счет маленьких функций не знаю, возможно привычка, а вообще для того, чтобы сохранить ссылку на объект vue и использовать её где-то внутри функции, где this будет ссылаться на область видимости самой функции
methods: {
someFunc() {
const vm = this
// _ = lodash
_.each([1,2,3], function(...args) {
// this == function(){}
// vm == vue
})
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question