//datatable js
export default{
  data(){
    return {
    };
  },
  mounted(){
    //onez.data(this,['items']);
    this.init();
  },
  watch:{
    data(){
      this.init();
    }
  },
  methods:{
    init(){
      if(this.data && this.data.js && this.data.js.length>0){
        this.$nextTick(()=>{
          if(this.data.jsBefore){
            eval(this.data.jsBefore);
          }
          if(this.data.jsUrl && this.data.jsUrl.length>0){
            this.loadJS(this.data.jsUrl);
          }else{
            this.runJS();
          }
        });
      }
    },
    loadJS(urls){
      if(urls.length<1){
        this.runJS();
      }else{
        var url=urls.shift();
        $.getScript(url,()=>{
          this.loadJS(urls);
        });
      }
    },
    runJS(){
      var that=this;
      eval(this.data.js);
    }
  }
}
