throttle
返回函数。所以调用
throttle()
并将其分配给
clickA
这样地:
<script lang="ts">
import Vue from 'vue'
import { Component } from 'vue-property-decorator'
import throttle from 'lodash/throttle'
@Component
export default class App extends Vue {
clickA = throttle(function () {
var date = new Date();
var time = date.toLocaleTimeString();
console.log('A clicked', time)
}, 1000) // max one submit per second
}
</script>
编辑:
<button type="button" @click="clickA">{{buttonText}}</button>
剧本
<script lang="ts">
import Vue from 'vue'
import { Component } from 'vue-property-decorator'
import throttle from 'lodash/throttle'
@Component
export default class App extends Vue {
buttonText = 'my button';
clickA = throttle( () => {
var date = new Date();
var time = date.toLocaleTimeString();
console.log('A clicked', time)
/// change button text
this.buttonText = 'my button' + time;
}, 1000) // max one submit per second
}
</script>