Skip to content

Commit 9dd24d5

Browse files
committed
fix popup-dialog双向绑定数据逻辑修正
1 parent f80ac03 commit 9dd24d5

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

Diff for: pages/index/index.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@
177177
// #endif
178178
],
179179
functionals: [
180-
// {
181-
// name: 'Calendar 日历',
182-
// url: 'calendar'
183-
// },
180+
{
181+
name: 'Calendar 日历',
182+
url: 'calendar'
183+
},
184184
{
185185
name: 'Collapse 折叠面板',
186186
url: 'collapse'

Diff for: pages/vue/popup/popup.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<view>
7777
<!-- 输入框示例 -->
7878
<uni-popup ref="inputDialog" type="dialog">
79-
<uni-popup-dialog ref="inputClose" :maxlength="10" mode="input" title="输入内容" value="对话框预置提示内容!"
79+
<uni-popup-dialog ref="inputClose" :maxlength="10" mode="input" title="输入内容" v-model="value"
8080
placeholder="请输入内容,限制10个字" @confirm="dialogInputConfirm"></uni-popup-dialog>
8181
</uni-popup>
8282
</view>

Diff for: uni_modules/uni-popup/components/uni-popup-dialog/uni-popup-dialog.vue

+27-8
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
* @value input 可输入对话框
5353
* @showClose {Boolean} 是否显示关闭按钮
5454
* @property {String} content 对话框内容
55-
* @property {Boolean} beforeClose 是否拦截取消事件
55+
* @property {Boolean} beforeClose 是否拦截取消事件
5656
* @property {Number} maxlength 输入
5757
* @event {Function} confirm 点击确认按钮触发
5858
* @event {Function} close 点击取消按钮触发
@@ -61,7 +61,7 @@
6161
export default {
6262
name: "uniPopupDialog",
6363
mixins: [popup],
64-
emits: ['confirm', 'close'],
64+
emits: ['confirm', 'close', 'update:modelValue', 'input'],
6565
props: {
6666
inputType: {
6767
type: String,
@@ -71,10 +71,20 @@
7171
type: Boolean,
7272
default: true
7373
},
74+
// #ifdef VUE2
7475
value: {
7576
type: [String, Number],
7677
default: ''
7778
},
79+
// #endif
80+
// #ifdef VUE3
81+
modelValue: {
82+
type: [Number, String],
83+
default: ''
84+
},
85+
// #endif
86+
87+
7888
placeholder: {
7989
type: [String, Number],
8090
default: ''
@@ -110,10 +120,10 @@
110120
maxlength: {
111121
type: Number,
112122
default: -1,
113-
},
114-
focus:{
115-
type: Boolean,
116-
default: true,
123+
},
124+
focus: {
125+
type: Boolean,
126+
default: true,
117127
}
118128
},
119129
data() {
@@ -151,6 +161,16 @@
151161
} else {
152162
this.val = val
153163
}
164+
},
165+
val(val) {
166+
// #ifdef VUE2
167+
// TODO 兼容 vue2
168+
this.$emit('input', val);
169+
// #endif
170+
// #ifdef VUE3
171+
// TODO 兼容 vue3
172+
this.$emit('update:modelValue', val);
173+
// #endif
154174
}
155175
},
156176
created() {
@@ -173,8 +193,7 @@
173193
this.$emit('confirm', this.val)
174194
} else {
175195
this.$emit('confirm')
176-
}
177-
this.$emit("input",this.val);
196+
}
178197
if (this.beforeClose) return
179198
this.popup.close()
180199
},

0 commit comments

Comments
 (0)