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

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

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