You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.6 KiB
84 lines
2.6 KiB
GV.init(function (_require) {
|
|
new (function () {
|
|
this.require = _require;
|
|
var Vue = this.Vue = _require('Vue');
|
|
|
|
var CleanVue = function () {
|
|
for (var i in Vue.options.components){
|
|
delete Vue.options.components[i];
|
|
}
|
|
};
|
|
|
|
|
|
this.VueRouter = _require('vue-router');
|
|
this.Vue.use(this.VueRouter);
|
|
this.axios = _require('axios');
|
|
var htmlparser2 = _require('htmlparser2');
|
|
axiosUse(this);
|
|
this.qs = _require('qs');
|
|
this.GoVueMount = function (app, context) {
|
|
var ctx = GetGoVueTemplate(GoHtmlSrc);
|
|
var cleanInlineJsCtx = GetGoVueTemplateInlineJs(ctx.template);
|
|
|
|
app.$options.template = ctx.content;
|
|
|
|
var template = ctx.template;
|
|
if (cleanInlineJsCtx){
|
|
template = cleanInlineJsCtx.template;
|
|
}
|
|
|
|
var renderer = _require('vue-server-renderer').createRenderer({
|
|
template: template
|
|
});
|
|
|
|
if (!context) {
|
|
context = {}
|
|
}
|
|
context.GoVueTemplate = "<go-vue-template style='display: none'>" + Base64Encode(encodeURIComponent(ctx.content)) + "</go-vue-template>"
|
|
context.GoVueData = "<go-vue-data style='display: none'>" + Base64Encode(encodeURIComponent(JSON.stringify(app.$data))) + "</go-vue-data>"
|
|
renderer.renderToString(app, context, function (err, html) {
|
|
if (err) {
|
|
CleanVue();
|
|
throw err
|
|
} else {
|
|
if (cleanInlineJsCtx){
|
|
html = html.replace("<!--gv-js-outlet-->",cleanInlineJsCtx.content);
|
|
}
|
|
GoReturn(html);
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
try {
|
|
eval(GoUseCallback)
|
|
} catch (e) {
|
|
GoSetError(JSON.stringify({
|
|
code: GoUseCallback,
|
|
error: e.toString(),
|
|
}));
|
|
CleanVue();
|
|
throw e
|
|
}
|
|
|
|
|
|
var codes = GetGoVueJsCode(htmlparser2, GoHtmlSrc)
|
|
// console.log(JSON.stringify(codes))
|
|
for (var i in codes) {
|
|
// console.log("with(this){\n" + codes[i] + "\n}");
|
|
try {
|
|
eval("with(this){\n" + codes[i] + "\n}")
|
|
} catch (e) {
|
|
GoSetError(JSON.stringify({
|
|
code: "with(this){\n" + codes[i] + "\n}",
|
|
error: e.toString(),
|
|
}));
|
|
CleanVue();
|
|
throw e
|
|
}
|
|
}
|
|
|
|
CleanVue();
|
|
|
|
})()
|
|
});
|