diff --git a/example/pages/rate/index.js b/example/pages/rate/index.js index 7cab03f1..2cfa2e28 100644 --- a/example/pages/rate/index.js +++ b/example/pages/rate/index.js @@ -7,13 +7,6 @@ Page({ value3: 3, value4: 2.5, value5: 4, - value6: 3 + value6: 3, }, - - onChange(event) { - const { key } = event.currentTarget.dataset; - this.setData({ - [key]: event.detail - }); - } }); diff --git a/example/pages/rate/index.wxml b/example/pages/rate/index.wxml index e469c3b8..3cce542b 100644 --- a/example/pages/rate/index.wxml +++ b/example/pages/rate/index.wxml @@ -1,8 +1,7 @@ @@ -11,53 +10,45 @@ custom-class="rate-position" icon="like" void-icon="like-o" - data-key="value2" - value="{{ value2 }}" + model:value="{{ value2 }}" /> @@ -66,7 +57,6 @@ diff --git a/example/project.config.json b/example/project.config.json index a85a795d..cb5b51bc 100644 --- a/example/project.config.json +++ b/example/project.config.json @@ -13,7 +13,7 @@ }, "compileType": "miniprogram", "cloudfunctionRoot": "functions/", - "libVersion": "2.3.0", + "libVersion": "2.9.3", "appid": "wx1c01b35002d3ba14", "projectname": "vant-weapp", "debugOptions": { diff --git a/packages/common/version.ts b/packages/common/version.ts new file mode 100644 index 00000000..593f9f5c --- /dev/null +++ b/packages/common/version.ts @@ -0,0 +1,33 @@ +import { getSystemInfoSync } from './utils'; + +function compareVersion(v1, v2) { + v1 = v1.split('.'); + v2 = v2.split('.'); + const len = Math.max(v1.length, v2.length); + + while (v1.length < len) { + v1.push('0'); + } + while (v2.length < len) { + v2.push('0'); + } + + for (let i = 0; i < len; i++) { + const num1 = parseInt(v1[i], 10); + const num2 = parseInt(v2[i], 10); + + if (num1 > num2) { + return 1; + } + if (num1 < num2) { + return -1; + } + } + + return 0; +} + +export function canIUseModel() { + const system = getSystemInfoSync(); + return compareVersion(system.SDKVersion, '2.9.3') >= 0; +} diff --git a/packages/field/index.ts b/packages/field/index.ts index 2016390d..700e0e88 100644 --- a/packages/field/index.ts +++ b/packages/field/index.ts @@ -1,6 +1,7 @@ import { VantComponent } from '../common/component'; import { Weapp } from 'definitions/weapp'; import { commonProps, inputProps, textareaProps } from './props'; +import { canIUseModel } from '../common/version'; VantComponent({ field: true, @@ -121,7 +122,9 @@ VantComponent({ }, emitChange() { - this.setData({ value: this.value }); + if (canIUseModel()) { + this.setData({ value: this.value }); + } wx.nextTick(() => { this.$emit('input', this.value); diff --git a/packages/rate/index.ts b/packages/rate/index.ts index fcad59bc..bb5d106b 100644 --- a/packages/rate/index.ts +++ b/packages/rate/index.ts @@ -1,5 +1,6 @@ import { VantComponent } from '../common/component'; import { Weapp } from 'definitions/weapp'; +import { canIUseModel } from '../common/version'; VantComponent({ field: true, @@ -64,8 +65,15 @@ VantComponent({ const { score } = event.currentTarget.dataset; if (!data.disabled && !data.readonly) { this.setData({ innerValue: score + 1 }); - this.$emit('input', score + 1); - this.$emit('change', score + 1); + + if (canIUseModel()) { + this.setData({ value: score + 1 }); + } + + wx.nextTick(() => { + this.$emit('input', score + 1); + this.$emit('change', score + 1); + }); } },