提交 a700b45b 编写于 作者: 郭胜强

Merge branch 'master' of github.com:dcloudio/uni-app

<template> <template>
<view class="uni-numbox"> <view class="uni-numbox">
<view class="uni-numbox-minus" :class="{'uni-numbox-disabled': disableSubtract}" @click="_subtract">-</view> <view class="uni-numbox-minus" :class="{'uni-numbox-disabled': disableSubtract}" @click="_calcValue('subtract')">-</view>
<input class="uni-numbox-value" type="number" :disabled="disabled" v-model="value" @blur="_handleBlur"> <input class="uni-numbox-value" type="number" :disabled="disabled" :value="inputValue" @blur="_onBlur">
<view class="uni-numbox-plus" :class="{'uni-numbox-disabled': disableAdd}" @click="_add">+</view> <view class="uni-numbox-plus" :class="{'uni-numbox-disabled': disableAdd}" @click="_calcValue('add')">+</view>
</view> </view>
</template> </template>
<script> <script>
...@@ -30,6 +30,11 @@ ...@@ -30,6 +30,11 @@
default: false default: false
} }
}, },
data() {
return {
inputValue: this.value
}
},
computed: { computed: {
disableSubtract() { disableSubtract() {
return this.value <= this.min return this.value <= this.min
...@@ -38,23 +43,18 @@ ...@@ -38,23 +43,18 @@
return this.value >= this.max return this.value >= this.max
} }
}, },
onUnload() { watch: {
// 目前为解决页面重新进入组件不更新的问题,这里主动重置下数据。 value(val) {
this.value = 0; this.inputValue = val;
this.step = 1; },
this.max = Infinity; inputValue(val) {
this.min = -Infinity; this.$emit('change', val);
}
}, },
methods: { methods: {
_subtract(evt) {
this._calcValue('subtract');
},
_add(evt) {
this._calcValue('add');
},
_calcValue(type) { _calcValue(type) {
const scale = this._getDecimalScale(); const scale = this._getDecimalScale();
let value = this.value * scale; let value = this.inputValue * scale;
let step = this.step * scale; let step = this.step * scale;
if (type === 'subtract') { if (type === 'subtract') {
...@@ -65,8 +65,7 @@ ...@@ -65,8 +65,7 @@
if (value < this.min || value > this.max) { if (value < this.min || value > this.max) {
return return
} }
console.log('value:' + value); this.inputValue = value / scale;
this.value = value / scale;
}, },
_getDecimalScale() { _getDecimalScale() {
let scale = 1; let scale = 1;
...@@ -76,10 +75,10 @@ ...@@ -76,10 +75,10 @@
} }
return scale; return scale;
}, },
_handleBlur(evt) { _onBlur(event) {
let value = evt.detail.value; let value = event.detail.value;
if (!value) { if (!value) {
this.value = 0; this.inputValue = 0;
return return
} }
value = +value; value = +value;
...@@ -88,12 +87,7 @@ ...@@ -88,12 +87,7 @@
} else if (value < this.min) { } else if (value < this.min) {
value = this.min value = this.min
} }
this.value = value this.inputValue = value
}
},
watch: {
value(val) {
this.$emit('update', val);
} }
} }
} }
......
<template> <template>
<view class="segmented-control" :class="styleType" :style="wrapStyle"> <view class="segmented-control" :class="styleType" :style="wrapStyle">
<view v-for="(item, index) in values" class="segmented-control-item" :class="styleType" :key="index" :style="index === current ? activeStyle : itemStyle" <view v-for="(item, index) in values" class="segmented-control-item" :class="styleType" :key="index" :style="index === currentIndex ? activeStyle : itemStyle"
@click="onClick(index)"> @click="onClick(index)">
{{item}} {{item}}
</view> </view>
</view> </view>
...@@ -30,6 +30,18 @@ ...@@ -30,6 +30,18 @@
default: 'button' default: 'button'
} }
}, },
data() {
return {
currentIndex: this.current
}
},
watch: {
current(val) {
if (val !== this.currentIndex) {
this.currentIndex = val;
}
}
},
computed: { computed: {
wrapStyle() { wrapStyle() {
let styleString = ''; let styleString = '';
...@@ -70,8 +82,8 @@ ...@@ -70,8 +82,8 @@
}, },
methods: { methods: {
onClick(index) { onClick(index) {
if (this.current !== index) { if (this.currentIndex !== index) {
this.current = index; this.currentIndex = index;
this.$emit('clickItem', index); this.$emit('clickItem', index);
} }
} }
...@@ -98,7 +110,7 @@ ...@@ -98,7 +110,7 @@
.segmented-control.text { .segmented-control.text {
border: 0; border: 0;
border-radius: 0upx; border-radius: 0upx;
} }
...@@ -120,4 +132,4 @@ ...@@ -120,4 +132,4 @@
.segmented-control-item:first-child { .segmented-control-item:first-child {
border-left-width: 0; border-left-width: 0;
} }
</style> </style>
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
/** /**
* 图标大小 * 图标大小
*/ */
size: Number size: [Number, String]
}, },
computed: { computed: {
fontSize() { fontSize() {
......
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
</view> </view>
<!-- #ifdef MP-WEIXIN --> <!-- #ifdef MP-WEIXIN -->
<button open-type="launchApp" app-parameter="uni-app" binderror="launchAppError">打开APP</button> <button open-type="launchApp" app-parameter="uni-app" binderror="launchAppError">打开APP</button>
<button open-type="feedback">意见反馈</button>
<!-- #endif --> <!-- #endif -->
<button open-type="feedback">意见反馈</button>
</view> </view>
</view> </view>
</view> </view>
...@@ -57,4 +57,4 @@ ...@@ -57,4 +57,4 @@
.mini-btn { .mini-btn {
margin-right: 10upx; margin-right: 10upx;
} }
</style> </style>
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<view class="item"> <view class="item">
<text class="item-title">获取输入框的值</text> <text class="item-title">获取输入框的值</text>
<view class="inline-item"> <view class="inline-item">
<number-box v-on:update="numberUpdate"></number-box> <number-box v-on:change="onNumberChange"></number-box>
<text class="item-label-right">当前的值为:{{numberValue}}</text> <text class="item-label-right">当前的值为:{{numberValue}}</text>
</view> </view>
</view> </view>
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
numberBox numberBox
}, },
methods: { methods: {
numberUpdate(value) { onNumberChange(value) {
this.numberValue = value; this.numberValue = value;
} }
} }
......
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
console.log(JSON.stringify(this.sendDate)); console.log(JSON.stringify(this.sendDate));
let imgs = this.imageList.map((value,index) => { let imgs = this.imageList.map((value,index) => {
return { return {
name: name: "images" + index, name: "images" + index,
uri: value uri: value
} }
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册