Skip to content

Commit

Permalink
fixed: uni-form get vm $option bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Fasttian committed Nov 18, 2020
1 parent 15282a9 commit 16bd1b4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/components/uni-forms/uni-forms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@
* @event {Function} submit 提交时触发
*/
import Vue from 'vue'
Vue.prototype.binddata = function(name, value, formName) {
Vue.prototype.binddata = function(name, value, formName) {
if (formName) {
this.$refs[formName].setValue(name, value)
} else {
let refName = null
let formVm
for (let i in this.$refs) {
if (this.$refs[i] && this.$refs[i].$options.name === 'uniForms') {
refName = i
const vm = this.$refs[i]
if (vm && vm.$options && vm.$options.name === 'uniForms') {
formVm = vm
break
}
}
if (!refName) return console.error('当前 uni-froms 组件缺少 ref 属性')
this.$refs[refName].setValue(name, value)
if (!formVm) return console.error('当前 uni-froms 组件缺少 ref 属性')
formVm.setValue(name, value)
}
}
Expand Down Expand Up @@ -107,11 +108,11 @@
this.formTrigger = trigger
},
value: {
handler(newVal) {
handler(newVal) {
if (this.isChildEdit) {
this.isChildEdit = false
return
}
}
this.childrens.forEach((item) => {
if (item.name) {
const formDataValue = newVal.hasOwnProperty(item.name) ? newVal[item.name] : null
Expand All @@ -124,7 +125,7 @@
},
created() {
let _this = this
this.childrens = []
this.childrens = []
this.inputChildrens = []
this.formRules = []
this.init(this.rules)
Expand Down Expand Up @@ -159,7 +160,7 @@
let example = this.childrens.find(child => child.name === name)
if (!example) return null
this.isChildEdit = true
value = this._getValue(example, value)
value = this._getValue(example, value)
this.formData[name] = value
example.val = value
this.$emit('input', Object.assign({}, this.value, this.formData))
Expand Down Expand Up @@ -200,7 +201,7 @@
* 触发表单校验,通过 @validate 获取
* @param {Object} validate
*/
validateCheck(validate) {
validateCheck(validate) {
if (validate === null) validate = null
this.$emit('validate', validate)
},
Expand Down Expand Up @@ -259,11 +260,11 @@
[i]: fieldsValue[i]
}, this.formData)
if (resultData) {
example = this.childrens.find(child => child.name === resultData.key)
const inputComp = this.inputChildrens.find(child=>child.rename === example.name)
if(inputComp){
inputComp.errMsg = resultData.errorMessage
}
example = this.childrens.find(child => child.name === resultData.key)
const inputComp = this.inputChildrens.find(child=>child.rename === example.name)
if(inputComp){
inputComp.errMsg = resultData.errorMessage
}
result.push(resultData)
if (this.errShowType === 'undertext') {
if (example) example.errMsg = resultData.errorMessage
Expand Down Expand Up @@ -304,8 +305,8 @@
callback && typeof callback === 'function' && callback(result, invalidFields)
if (promise && callback) {
return promise
}else{
return null
}else{
return null
}
},
Expand All @@ -314,7 +315,7 @@
* 手动提交校验表单
* 对整个表单进行校验的方法,参数为一个回调函数。
*/
submit(callback) {
submit(callback) {
// Object.assign(this.formData,formData)
return this.validateAll(this.formData, 'submit', callback)
},
Expand Down Expand Up @@ -394,14 +395,14 @@
}
</script>

<style lang="scss" scoped>
.uni-forms {
overflow: hidden;
// padding: 10px 15px;
// background-color: #fff;
<style lang="scss" scoped>
.uni-forms {
overflow: hidden;
// padding: 10px 15px;
// background-color: #fff;
}
.uni-forms--top {
.uni-forms--top {
padding: 10px 15px;
// padding-top: 22px;
}
</style>
</style>
14 changes: 14 additions & 0 deletions src/pages/vue/goods-nav/goods-nav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,18 @@
/* #endif */
bottom: 0;
}
/* #ifdef H5 */
@media screen and (min-width: 768px, max-width: 1425px) {
.swiper {
height: 630px;
}
}
@media screen and (min-width: 1425px) {
.swiper {
height: 830px;
}
}
/* #endif */
</style>

0 comments on commit 16bd1b4

Please sign in to comment.