jquery加载单文件vue组件的方法

/**注册组件 */ function registerComponent(name){ dm[name] = {}; Vue.component(name + '-component', function(resolve, reject){ $.get('./modules/' + name + '.vue').then(function(rv){ var temp = rv.match(/<template[^>]*>([\s\S]*?)<\/template>/)[1].replace(/(^\s+)|\n/g, ''), script = rv.match(/<script[^>]*>([\s\S]*?)<\/script>/)[1].replace(/(^\s+)|\n/g, ''); script = (new Function('return ' + script))(); script.template = temp; script.props || (script.props=["param"]); script.data || (script.data=function(){ return JSON.parse(JSON.stringify(this.param))}); resolve(script); }).catch(function(err){ console.error(err); resolve({ template: '<div>NOT FOUND</div>' }); }); }); }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyxyjj.html