vue 使用underscore lodash debounce throttle

在解析研究underscore, lodash源码,的使用,我想underscore 引入vue,本来很简单的事情

第一步: npm install  underscore --save 

第二,在 自己的组件内 引入 import _ from "underscore"

第三使用:  使用, 这时候出问题了, arr 方法 obj 方法都是好用的正常的,例如 

var numbers = [10, 5, 100, 2, 1000];
_.min(numbers);
=> 

但是!!! 但是!!!当我使用 Functions

  • bind
  • bindAll
  • partial
  • memoize
  • delay
  • defer
  • throttle
  • debounce
  • once
  • after
  • before
  • wrap
  • negate
  • compose
  • restArguments 的时候,以debounce 为例子,这货竟然失效,我打印 这个函数显示函数是存在的,
  • 然后 经过资料查阅发现,我们 应该在vue的methods方法中这样写
  • // 正确写法
  • lookUnderscore:_.debounce(function(){

    console.log(11111)

    },2000,false),

  • //错误写法

    aaa(){ //方法aaa

    _.debounce(function(){

    console.log(11111)

    },2000,false),

    }

发布了124 篇原创文章 · 获赞 10 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_40774743/article/details/89333697