Commit 314bc7b7 by Moxun1639

解决组件实例与crud,及其中page、pagination、form未进行绑定关联

parent 204710f2
...@@ -597,6 +597,12 @@ function presenter(crud) { ...@@ -597,6 +597,12 @@ function presenter(crud) {
console.warn('[CRUD warn]: ' + 'please use $options.cruds() { return CRUD(...) or [CRUD(...), ...] }') console.warn('[CRUD warn]: ' + 'please use $options.cruds() { return CRUD(...) or [CRUD(...), ...] }')
} }
return { return {
data() {
// 在data中返回crud,是为了将crud与当前实例关联,组件观测crud相关属性变化
return {
crud: this.crud
}
},
beforeCreate() { beforeCreate() {
this.$crud = this.$crud || {} this.$crud = this.$crud || {}
let cruds = this.$options.cruds instanceof Function ? this.$options.cruds() : crud let cruds = this.$options.cruds instanceof Function ? this.$options.cruds() : crud
...@@ -610,12 +616,7 @@ function presenter(crud) { ...@@ -610,12 +616,7 @@ function presenter(crud) {
this.$crud[ele.tag] = ele this.$crud[ele.tag] = ele
ele.registerVM('presenter', this, 0) ele.registerVM('presenter', this, 0)
}) })
this.crud = this.$crud['defalut'] || cruds.length > 0 ? cruds[0] : null this.crud = this.$crud['defalut'] || cruds[0]
},
data() {
return {
searchToggle: true
}
}, },
methods: { methods: {
parseTime parseTime
...@@ -657,9 +658,14 @@ function presenter(crud) { ...@@ -657,9 +658,14 @@ function presenter(crud) {
*/ */
function header() { function header() {
return { return {
data() {
return {
crud: this.crud,
query: this.crud.query
}
},
beforeCreate() { beforeCreate() {
this.crud = lookupCrud(this) this.crud = lookupCrud(this)
this.query = this.crud.query
this.crud.registerVM('header', this, 1) this.crud.registerVM('header', this, 1)
}, },
destroyed() { destroyed() {
...@@ -673,9 +679,14 @@ function header() { ...@@ -673,9 +679,14 @@ function header() {
*/ */
function pagination() { function pagination() {
return { return {
data() {
return {
crud: this.crud,
page: this.crud.page
}
},
beforeCreate() { beforeCreate() {
this.crud = lookupCrud(this) this.crud = lookupCrud(this)
this.page = this.crud.page
this.crud.registerVM('pagination', this, 2) this.crud.registerVM('pagination', this, 2)
}, },
destroyed() { destroyed() {
...@@ -689,9 +700,14 @@ function pagination() { ...@@ -689,9 +700,14 @@ function pagination() {
*/ */
function form(defaultForm) { function form(defaultForm) {
return { return {
data() {
return {
crud: this.crud,
form: this.crud.form
}
},
beforeCreate() { beforeCreate() {
this.crud = lookupCrud(this) this.crud = lookupCrud(this)
this.form = this.crud.form
this.crud.registerVM('form', this, 3) this.crud.registerVM('form', this, 3)
}, },
created() { created() {
...@@ -713,6 +729,11 @@ function crud(options = {}) { ...@@ -713,6 +729,11 @@ function crud(options = {}) {
} }
options = mergeOptions(defaultOptions, options) options = mergeOptions(defaultOptions, options)
return { return {
data() {
return {
crud: this.crud
}
},
beforeCreate() { beforeCreate() {
this.crud = lookupCrud(this) this.crud = lookupCrud(this)
this.crud.registerVM(options.type, this) this.crud.registerVM(options.type, this)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment