zoukankan      html  css  js  c++  java
  • 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[^>]*>([sS]*?)</template>/)[1].replace(/(^s+)|
    /g, ''),
                        script = rv.match(/<script[^>]*>([sS]*?)</script>/)[1].replace(/(^s+)|
    /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>'
                    });
                });
            });
        }
  • 相关阅读:
    day89
    day88
    day87
    day86
    day85
    day84
    day83
    Maven仓库汇总
    [转载]AngularJS入门教程04:双向绑定
    [转载]AngularJS入门教程03:迭代器
  • 原文地址:https://www.cnblogs.com/zh33gl/p/7052567.html
Copyright © 2011-2022 走看看