mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-22 22:49:15 +08:00
[Improvement] optimize watcher (#1001)
This commit is contained in:
parent
6d4709cc71
commit
ba2f11138b
@ -83,18 +83,9 @@ export default create({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
|
||||||
this.render();
|
|
||||||
},
|
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
rate() {
|
rate: {
|
||||||
this.render();
|
handler() {
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
render() {
|
|
||||||
this.startTime = Date.now();
|
this.startTime = Date.now();
|
||||||
this.startRate = this.value;
|
this.startRate = this.value;
|
||||||
this.endRate = this.format(this.rate);
|
this.endRate = this.format(this.rate);
|
||||||
@ -107,7 +98,11 @@ export default create({
|
|||||||
this.$emit('input', this.endRate);
|
this.$emit('input', this.endRate);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
immediate: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
animate() {
|
animate() {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const progress = Math.min((now - this.startTime) / this.duration, 1);
|
const progress = Math.min((now - this.startTime) / this.duration, 1);
|
||||||
|
@ -58,19 +58,22 @@ export default create({
|
|||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
type: {
|
value: null,
|
||||||
type: String,
|
|
||||||
default: 'text'
|
|
||||||
},
|
|
||||||
value: {},
|
|
||||||
icon: String,
|
icon: String,
|
||||||
label: String,
|
label: String,
|
||||||
error: Boolean,
|
error: Boolean,
|
||||||
center: Boolean,
|
center: Boolean,
|
||||||
border: Boolean,
|
|
||||||
required: Boolean,
|
required: Boolean,
|
||||||
autosize: [Boolean, Object],
|
autosize: [Boolean, Object],
|
||||||
errorMessage: String,
|
errorMessage: String,
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: 'text'
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
onIconClick: {
|
onIconClick: {
|
||||||
type: Function,
|
type: Function,
|
||||||
default: () => {}
|
default: () => {}
|
||||||
|
@ -69,12 +69,14 @@ export default create({
|
|||||||
iconName() {
|
iconName() {
|
||||||
return this.mode === 'closeable' ? 'close' : this.mode === 'link' ? 'arrow' : '';
|
return this.mode === 'closeable' ? 'close' : this.mode === 'link' ? 'arrow' : '';
|
||||||
},
|
},
|
||||||
|
|
||||||
barStyle() {
|
barStyle() {
|
||||||
return {
|
return {
|
||||||
color: this.color,
|
color: this.color,
|
||||||
background: this.background
|
background: this.background
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
contentStyle() {
|
contentStyle() {
|
||||||
return {
|
return {
|
||||||
paddingLeft: this.firstRound ? 0 : this.wrapWidth + 'px',
|
paddingLeft: this.firstRound ? 0 : this.wrapWidth + 'px',
|
||||||
@ -84,13 +86,21 @@ export default create({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
|
||||||
this.initAnimation();
|
|
||||||
},
|
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
text: function() {
|
text: {
|
||||||
this.$nextTick(this.initAnimation);
|
handler() {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
const offsetWidth = this.$refs.content.getBoundingClientRect().width;
|
||||||
|
const wrapWidth = this.$refs.wrap.getBoundingClientRect().width;
|
||||||
|
if (this.scrollable && offsetWidth > wrapWidth) {
|
||||||
|
this.wrapWidth = wrapWidth;
|
||||||
|
this.offsetWidth = offsetWidth;
|
||||||
|
this.duration = offsetWidth / this.speed;
|
||||||
|
this.animationClass = this.b('play');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -105,17 +115,6 @@ export default create({
|
|||||||
this.duration = (this.offsetWidth + this.wrapWidth) / this.speed;
|
this.duration = (this.offsetWidth + this.wrapWidth) / this.speed;
|
||||||
this.animationClass = this.b('play--infinite');
|
this.animationClass = this.b('play--infinite');
|
||||||
});
|
});
|
||||||
},
|
|
||||||
|
|
||||||
initAnimation() {
|
|
||||||
const offsetWidth = this.$refs.content.getBoundingClientRect().width;
|
|
||||||
const wrapWidth = this.$refs.wrap.getBoundingClientRect().width;
|
|
||||||
if (this.scrollable && offsetWidth > wrapWidth) {
|
|
||||||
this.wrapWidth = wrapWidth;
|
|
||||||
this.offsetWidth = offsetWidth;
|
|
||||||
this.duration = offsetWidth / this.speed;
|
|
||||||
this.animationClass = this.b('play');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -118,13 +118,12 @@ export default create({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
|
||||||
this.selectPage(this.value);
|
|
||||||
},
|
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
value(page) {
|
value: {
|
||||||
this.selectPage(page);
|
handler(page) {
|
||||||
|
this.selectPage(page || this.value);
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -70,13 +70,14 @@ export default create({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
|
||||||
this.initColumns();
|
|
||||||
},
|
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
columns() {
|
columns: {
|
||||||
this.initColumns();
|
handler() {
|
||||||
|
const columns = this.columns.map(deepClone);
|
||||||
|
this.isSimpleColumn = columns.length && !columns[0].values;
|
||||||
|
this.currentColumns = this.isSimpleColumn ? [{ values: columns }] : columns;
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -95,12 +96,6 @@ export default create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
initColumns() {
|
|
||||||
const columns = this.columns.map(deepClone);
|
|
||||||
this.isSimpleColumn = columns.length && !columns[0].values;
|
|
||||||
this.currentColumns = this.isSimpleColumn ? [{ values: columns }] : columns;
|
|
||||||
},
|
|
||||||
|
|
||||||
emit(event) {
|
emit(event) {
|
||||||
if (this.isSimpleColumn) {
|
if (this.isSimpleColumn) {
|
||||||
this.$emit(event, this.getColumnValue(0), this.getColumnIndex(0));
|
this.$emit(event, this.getColumnValue(0), this.getColumnIndex(0));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user