欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery加載單文件vue組件的方法

 更新時(shí)間:2017年06月20日 09:07:12   作者:zh33gl  
這篇文章主要介紹了jquery加載單文件vue組件的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文為大家分享了jquery加載單文件vue組件的方法,供大家參考,具體內(nèi)容如下

/**注冊(cè)組件 */
  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>'
        });
      });
    });
  }

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論