diff --git a/packages/checkbox/index.ts b/packages/checkbox/index.ts
index 95f29f23..f9b30f99 100644
--- a/packages/checkbox/index.ts
+++ b/packages/checkbox/index.ts
@@ -1,5 +1,4 @@
import { VantComponent } from '../common/component';
-import { addUnit } from '../common/utils';
function emit(target: WechatMiniprogram.Component.TrivialInstance, value: boolean | any[]) {
target.$emit('input', value);
@@ -35,14 +34,10 @@ VantComponent({
},
iconSize: {
type: null,
- observer: 'setSizeWithUnit'
+ value: 20
}
},
- data: {
- sizeWithUnit: '20px'
- },
-
methods: {
emitChange(value: boolean) {
if (this.parent) {
@@ -87,12 +82,6 @@ VantComponent({
emit(parent, parentValue);
}
}
- },
-
- setSizeWithUnit(size: string | number): void {
- this.set({
- sizeWithUnit: addUnit(size)
- });
- },
+ }
}
});
diff --git a/packages/checkbox/index.wxml b/packages/checkbox/index.wxml
index 65124a16..19a89260 100644
--- a/packages/checkbox/index.wxml
+++ b/packages/checkbox/index.wxml
@@ -8,7 +8,7 @@
name="success"
size="0.8em"
class="{{ utils.bem('checkbox__icon', [shape, { disabled, checked: value }]) }}"
- style="font-size: {{ sizeWithUnit }};{{ checkedColor && value && !disabled ? 'border-color:' + checkedColor + '; background-color:' + checkedColor : '' }}"
+ style="font-size: {{ utils.addUnit(iconSize) }};{{ checkedColor && value && !disabled ? 'border-color:' + checkedColor + '; background-color:' + checkedColor : '' }}"
custom-class="icon-class"
custom-style="line-height: 1.25em;"
/>
diff --git a/packages/dialog/index.ts b/packages/dialog/index.ts
index e8195b77..d945d568 100644
--- a/packages/dialog/index.ts
+++ b/packages/dialog/index.ts
@@ -1,7 +1,6 @@
import { VantComponent } from '../common/component';
import { button } from '../mixins/button';
import { openType } from '../mixins/open-type';
-import { addUnit } from '../common/utils';
import { GRAY, BLUE } from '../common/color';
type Action = 'confirm' | 'cancel' | 'overlay';
@@ -23,10 +22,7 @@ VantComponent({
showCancelButton: Boolean,
closeOnClickOverlay: Boolean,
confirmButtonOpenType: String,
- width: {
- type: null,
- observer: 'setWidthWithUnit'
- },
+ width: null,
zIndex: {
type: Number,
value: 2000
@@ -125,12 +121,6 @@ VantComponent({
if (callback) {
callback(this);
}
- },
-
- setWidthWithUnit(val) {
- this.setData({
- widthWithUnit: addUnit(val)
- });
}
}
});
diff --git a/packages/dialog/index.wxml b/packages/dialog/index.wxml
index 854e8a14..5442c799 100644
--- a/packages/dialog/index.wxml
+++ b/packages/dialog/index.wxml
@@ -1,10 +1,12 @@
+
+
+
+
-
+
diff --git a/packages/progress/index.ts b/packages/progress/index.ts
index 5f9ce1c2..cd04f3e2 100644
--- a/packages/progress/index.ts
+++ b/packages/progress/index.ts
@@ -1,6 +1,5 @@
import { VantComponent } from '../common/component';
import { BLUE } from '../common/color';
-import { addUnit } from '../common/utils';
VantComponent({
props: {
@@ -23,19 +22,7 @@ VantComponent({
},
strokeWidth: {
type: null,
- observer: 'setStrokeWidthUnit'
- }
- },
-
- data: {
- strokeWidthUnit: '4px'
- },
-
- methods: {
- setStrokeWidthUnit(val) {
- this.setData({
- strokeWidthUnit: addUnit(val)
- });
+ value: 4
}
}
});
diff --git a/packages/progress/index.wxml b/packages/progress/index.wxml
index 5d27517d..e5981f09 100644
--- a/packages/progress/index.wxml
+++ b/packages/progress/index.wxml
@@ -1,8 +1,9 @@
+
-
+
diff --git a/packages/uploader/index.ts b/packages/uploader/index.ts
index 0fcabee1..2edc9ec0 100644
--- a/packages/uploader/index.ts
+++ b/packages/uploader/index.ts
@@ -1,6 +1,5 @@
import { VantComponent } from '../common/component';
import { isImageFile } from './utils';
-import { addUnit } from '../common/utils';
VantComponent({
props: {
@@ -11,8 +10,7 @@ VantComponent({
useBeforeRead: Boolean,
previewSize: {
type: null,
- value: 90,
- observer: 'setComputedPreviewSize'
+ value: 90
},
name: {
type: [Number, String],
@@ -70,12 +68,6 @@ VantComponent({
this.setData({ lists, isInCount: lists.length < maxCount });
},
- setComputedPreviewSize(val) {
- this.setData({
- computedPreviewSize: addUnit(val)
- });
- },
-
startUpload() {
if (this.data.disabled) return;
const {
diff --git a/packages/uploader/index.wxml b/packages/uploader/index.wxml
index 02546aa9..0a84848c 100644
--- a/packages/uploader/index.wxml
+++ b/packages/uploader/index.wxml
@@ -15,14 +15,14 @@
src="{{ item.url || item.path }}"
alt="{{ item.name || ('图片' + index) }}"
class="van-uploader__preview-image"
- style="width: {{ computedPreviewSize }}; height: {{ computedPreviewSize }};"
+ style="width: {{ utils.addUnit(previewSize) }}; height: {{ utils.addUnit(previewSize) }};"
data-url="{{ item.url || item.path }}"
bind:tap="doPreviewImage"
/>
{{ item.name || item.url || item.path }}
@@ -46,7 +46,7 @@
diff --git a/packages/wxs/add-unit.wxs b/packages/wxs/add-unit.wxs
new file mode 100644
index 00000000..27a22d82
--- /dev/null
+++ b/packages/wxs/add-unit.wxs
@@ -0,0 +1,14 @@
+/* eslint-disable */
+var REGEXP = getRegExp('^\d+(\.\d+)?$');
+
+function addUnit(value) {
+ if (value == null) {
+ return undefined;
+ }
+
+ return REGEXP.test('' + value) ? value + 'px' : value;
+}
+
+module.exports = {
+ addUnit: addUnit
+};
diff --git a/packages/wxs/utils.wxs b/packages/wxs/utils.wxs
index a18662df..d5c9d8c2 100644
--- a/packages/wxs/utils.wxs
+++ b/packages/wxs/utils.wxs
@@ -1,7 +1,10 @@
+/* eslint-disable */
var bem = require('./bem.wxs').bem;
var memoize = require('./memoize.wxs').memoize;
+var addUnit = require('./add-unit.wxs').addUnit;
module.exports = {
bem: memoize(bem),
- memoize: memoize
+ memoize: memoize,
+ addUnit: addUnit
};