diff --git a/lib/renderer/renderer.js b/lib/renderer/renderer.js
index 693653c..95ea1bc 100644
--- a/lib/renderer/renderer.js
+++ b/lib/renderer/renderer.js
@@ -66,6 +66,7 @@ class Renderer {
this.internalCache = new Utils.Cache();
this.head = options.head || {};
this.data = options.data || {};
+ this.propsData = options.propsData || {};
this.template = options.template || {};
const version = Utils.VueVersion(options.vueVersion);
if (version.enabled) {
@@ -128,6 +129,14 @@ class Renderer {
return mergedData;
};
}
+ /**
+ * @param {Object} oldPropsData
+ * @param {Object} newPropsData
+ * @returns {Function}
+ */
+ FixPropsData(oldPropsData, newPropsData) {
+ return Object.assign({}, oldPropsData, this.propsData, newPropsData);
+ }
/**
* @param {string} componentFile
* @param {string} filePath
@@ -396,15 +405,19 @@ class Renderer {
*
* @param {string} filePath
* @param {Object} data
+ * @param {Object} vueOptions
* @returns {Promise<{vue: object, css: string, script: string}>}
*/
- MakeVueClass(filePath, data) {
+ MakeVueClass(filePath, data, vueOptions = {}) {
return new Promise((resolve, reject) => {
let cachedBundle = this.internalCache.get(filePath);
if (cachedBundle) {
if (cachedBundle.bundle.data && typeof cachedBundle.bundle.data === "function") {
cachedBundle.bundle.data = this.FixData(cachedBundle.bundle.data(), data);
}
+ if (vueOptions.propsData && (cachedBundle.bundle.propsData || cachedBundle.bundle.props)) {
+ cachedBundle.bundle.propsData = this.FixPropsData(cachedBundle.bundle.propsData || {}, vueOptions.propsData);
+ }
// @ts-ignore
const vue = new Vue(cachedBundle.bundle);
const cleanBundle = this._deleteCtor(cachedBundle.bundle);
@@ -425,6 +438,10 @@ class Renderer {
if (bundle.data && typeof bundle.data === "function") {
bundle.data = this.FixData(bundle.data(), data);
}
+ //Insert propsData
+ if (vueOptions.propsData && (bundle.propsData || bundle.props)) {
+ bundle.propsData = this.FixPropsData(bundle.propsData || {}, vueOptions.propsData);
+ }
//Create Vue Class
// @ts-ignore
@@ -501,7 +518,7 @@ class Renderer {
return new Promise((resolve, reject) => {
this.FindFile(vueFile)
.then(filePath => {
- this.MakeVueClass(filePath, data)
+ this.MakeVueClass(filePath, data, vueOptions)
.then(vueClass => {
const mergedHeadObject = Utils.MergeHead(vueOptions.head, this.head);
const template = Object.assign({}, this.template, vueOptions.template);
@@ -536,7 +553,7 @@ class Renderer {
return new Promise((resolve, reject) => {
this.FindFile(vueFile)
.then(filePath => {
- this.MakeVueClass(filePath, data)
+ this.MakeVueClass(filePath, data, vueOptions)
.then(vueClass => {
const mergedHeadObject = Utils.MergeHead(vueOptions.head, this.head);
const headString = Utils.BuildHead(mergedHeadObject);
diff --git a/package.json b/package.json
index c83a4de..fa66680 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vue-pronto",
- "version": "1.7.0",
+ "version": "1.7.1",
"description": "Seriously fast vue server renderer",
"main": "lib/index.js",
"files": [
diff --git a/tests/example/views/index/index-with-props.vue b/tests/example/views/index/index-with-props.vue
new file mode 100644
index 0000000..842f90b
--- /dev/null
+++ b/tests/example/views/index/index-with-props.vue
@@ -0,0 +1,51 @@
+
+ {{bar}} Welcome to the {{title}} demo. Click a link: import fooTransitionExpand from '@foo/styles-animation/src/components/foo-transition-expand.vue'; const test = require("foo.vue"); const bar = require("bar.vue");{{msg}}
+ {{title}}
+
Welcome to the demo. Click a link:
import fooTransitionExpand from '@foo/styles-animation/src/components/foo-transition-expand.vue';
const test = require("foo.vue");
const bar = require("bar.vue");
Hello From Component in node_modules
FAKEHTML
' + }; + const renderer = new Pronto({ rootPath: rootPath, propsData: propsData }); + + const templateLiteral = `\n\n\ntrue
FAKEHTML
Welcome to the demo. Click a link:
import fooTransitionExpand from '@foo/styles-animation/src/components/foo-transition-expand.vue';
const test = require("foo.vue");
const bar = require("bar.vue");
Hello From Component in node_modules