watch: {
iconAndText: {
handler: function() {
// 防抖 300秒触发一次
this.debounce(this.assignment, 300)
},
deep: true
},
},
methods: {
// 防抖
debounce(fn, wait) {
if (this.fun !== null) {
clearTimeout(this.fun);
}
this.fun = setTimeout(fn, wait);
},
// 参数赋值到图片中
assignment() {
// 图标大小
this.$refs.iconImg.style.width = parseInt(this.iconAndText.iconSize) + 16 + "px";
this.$refs.iconImg.style.height = parseInt(this.iconAndText.iconSize) + 16 + "px";
// 文字颜色
this.$refs.txt1.style.color = this.iconAndText.fontColor;
this.$refs.txt2.style.color = this.iconAndText.fontColor;
// 文字样式
this.$refs.txt1.style.fontFamily = this.iconAndText.fontType;
this.$refs.txt2.style.fontFamily = this.iconAndText.fontType;
// 字体大小
this.$refs.txt1.style.fontSize = this.iconAndText.fontSize;
this.$refs.txt2.style.fontSize = this.iconAndText.fontSize;
// 行间距
this.$refs.txt1.style.marginBottom = this.iconAndText.fontSpace;
},
watch监听对象加防抖
最新推荐文章于 2024-05-16 09:49:11 发布