From 607ca3a52f33a14e83533b5f8c34252016c819c3 Mon Sep 17 00:00:00 2001
From: Tevin <tingquanren@163.com>
Date: Wed, 09 Dec 2020 10:44:24 +0800
Subject: [PATCH] 允许 polit 在 createOptions 时,插入 data

---
 bases/Pilot.js |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/bases/Pilot.js b/bases/Pilot.js
index a8fc753..bc09f48 100644
--- a/bases/Pilot.js
+++ b/bases/Pilot.js
@@ -12,7 +12,7 @@
         return {};
     }
 
-    createOptions() {
+    createOptions(dataAdd) {
         const options = {
             methods: {},
         };
@@ -21,7 +21,18 @@
                 return;
             }
             if (/^\$/.test(name)) {
-                options[name.replace('$', '')] = this[name];
+                if (name === '$data' && typeof dataAdd !== 'undefined') {
+                    // 当有传data值进来,初始值必须带data中的字段
+                    const dataOrig = this.$data();
+                    options.data = () => {
+                        return {
+                            ...dataOrig,
+                            ...dataAdd,
+                        }
+                    }
+                } else {
+                    options[name.replace('$', '')] = this[name];
+                }
             } else {
                 options.methods[name] = this[name];
             }

--
Gitblit v1.9.1