From 314bc7b7509d1268047de6f4650317401d42bd7e Mon Sep 17 00:00:00 2001 From: Moxun1639 Date: Sun, 8 Mar 2020 19:16:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=BB=84=E4=BB=B6=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E4=B8=8Ecrud=EF=BC=8C=E5=8F=8A=E5=85=B6=E4=B8=ADpage?= =?UTF-8?q?=E3=80=81pagination=E3=80=81form=E6=9C=AA=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Crud/crud.js | 39 ++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/components/Crud/crud.js b/src/components/Crud/crud.js index 133f01e..121b7e4 100644 --- a/src/components/Crud/crud.js +++ b/src/components/Crud/crud.js @@ -597,6 +597,12 @@ function presenter(crud) { console.warn('[CRUD warn]: ' + 'please use $options.cruds() { return CRUD(...) or [CRUD(...), ...] }') } return { + data() { + // 在data中返回crud,是为了将crud与当前实例关联,组件观测crud相关属性变化 + return { + crud: this.crud + } + }, beforeCreate() { this.$crud = this.$crud || {} let cruds = this.$options.cruds instanceof Function ? this.$options.cruds() : crud @@ -610,12 +616,7 @@ function presenter(crud) { this.$crud[ele.tag] = ele ele.registerVM('presenter', this, 0) }) - this.crud = this.$crud['defalut'] || cruds.length > 0 ? cruds[0] : null - }, - data() { - return { - searchToggle: true - } + this.crud = this.$crud['defalut'] || cruds[0] }, methods: { parseTime @@ -657,9 +658,14 @@ function presenter(crud) { */ function header() { return { + data() { + return { + crud: this.crud, + query: this.crud.query + } + }, beforeCreate() { this.crud = lookupCrud(this) - this.query = this.crud.query this.crud.registerVM('header', this, 1) }, destroyed() { @@ -673,9 +679,14 @@ function header() { */ function pagination() { return { + data() { + return { + crud: this.crud, + page: this.crud.page + } + }, beforeCreate() { this.crud = lookupCrud(this) - this.page = this.crud.page this.crud.registerVM('pagination', this, 2) }, destroyed() { @@ -689,9 +700,14 @@ function pagination() { */ function form(defaultForm) { return { + data() { + return { + crud: this.crud, + form: this.crud.form + } + }, beforeCreate() { this.crud = lookupCrud(this) - this.form = this.crud.form this.crud.registerVM('form', this, 3) }, created() { @@ -713,6 +729,11 @@ function crud(options = {}) { } options = mergeOptions(defaultOptions, options) return { + data() { + return { + crud: this.crud + } + }, beforeCreate() { this.crud = lookupCrud(this) this.crud.registerVM(options.type, this)