|
|
|
@ -11,16 +11,22 @@ function copy(from, to) {
|
|
|
|
|
//eval解析vue组件
|
|
|
|
|
function parseModel(response) {
|
|
|
|
|
var html = new DOMParser().parseFromString(response.data, 'text/html');
|
|
|
|
|
var template = html.getElementsByTagName('template')[0].innerHTML;
|
|
|
|
|
var template = html.getElementsByTagName('template')[0];
|
|
|
|
|
var script = html.getElementsByTagName('script')[0].innerHTML;
|
|
|
|
|
script = '(' + script.replace(/^\s*export\s*default\s*/, '').replace(/;?\s*$/, '') + ')\n//# sourceURL=' + response.config.url;
|
|
|
|
|
var model = eval(script);
|
|
|
|
|
if (model) {
|
|
|
|
|
model.template = template;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.error('eval error');
|
|
|
|
|
var model = eval(script) || {};
|
|
|
|
|
if (html.getElementsByTagName('style').length > 0) {
|
|
|
|
|
var hash = response.config.url;
|
|
|
|
|
var style = html.getElementsByTagName('style')[0];
|
|
|
|
|
style.setAttribute('data-vue-style', hash);
|
|
|
|
|
var styleValue = style.outerHTML.replace('[component]', "[data-vue-style='" + hash + "']");
|
|
|
|
|
if ($("style[data-vue-style='" + hash + "']").length === 0) {
|
|
|
|
|
$('head').append(styleValue);
|
|
|
|
|
}
|
|
|
|
|
template.content.children[0].setAttribute('data-vue-style', hash);
|
|
|
|
|
model.template = template.outerHTML;
|
|
|
|
|
}
|
|
|
|
|
model.template = template;
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
//循环添加vue组件
|
|
|
|
|