[vue] 说下 a t t r s 和 attrs和 attrs和listeners的使用场景
<template>
<el-button v-on="$listeners" v-bind="$attrs" :loading="loading" @click="myClick">
<slot></slot>
</el-button>
</template>
<script>
export default {
name: 'mButton',
inheritAttrs: false,
props: {
debounce: {
type: [Boolean, Number]
}
},
data() {
return {
timer: 0,
loading: false
}
},
methods: {
myClick() {
if (!this.debounce) return
this.loading = true
clearTimeout(this.timer)
this.timer = setTimeout(
() => {
this.loading = false
},
typeof this.debounce === 'boolean' ? 500 : this.debounce
)
}
}
}
</script>
个人简介
我是歌谣,欢迎和大家一起交流前后端知识。放弃很容易,
但坚持一定很酷。欢迎大家一起讨论
浙公网安备 33010602011771号