一、css:

<style scoped>
    @import 'https://unpkg.com/element-ui@2.3.7/lib/theme-chalk/index.css';
</style>

二、js:

第一种方式:利用Vue的mounted生命周期

mounted() {
    const oScript = document.createElement('script');
    oScript.type = 'text/javascript';
    oScript.src = 'https://unpkg.com/element-ui@2.3.7/lib/index.js';
    document.body.appendChild(oScript);
}

第二种方式:利用Vue的createElement方法

components: {
    'scriptLink': {
      render(createElement) {
        return createElement(
          'script',
          {
            attrs: {
              type: 'text/javascript',
              src: 'https://unpkg.com/element-ui@2.3.7/lib/index.js',
            },
          },
        )
      }
    }
  }

然后通过<scriptLink></scriptLink>  引入到组件中

第三种方封装一个remoteJs 组件

<template>
    <remote-js src="'https://unpkg.com/element-ui@2.3.7/lib/index.js'"></remote-js>
</template>
<script>
export default {
    components: {
    'remote-js': {
      render(createElement) {
        return createElement('script', {attrs: {type: 'text/javascript', src: this.src}});
      },
      props: {
        src: { type: String, required: true}
      }
    }
  }
}
</script>

 

Logo

前往低代码交流专区

更多推荐