jquery加载单文件vue组件

Posted 风的线条

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 style="text-align:center; line-height:5em;">NOT FOUND</div>‘
                });
            });
        });
    }

 

以上是关于jquery加载单文件vue组件的主要内容,如果未能解决你的问题,请参考以下文章