vue 动态调用远程js、css

2020-08-01 18:24
136
0

通过createElement 创建一个元素<script></ script> ,引入js

export default {
 components: {
  'remote-js': {
  render(createElement) {
   return createElement('script', { attrs: { type: 'text/javascript', src: this.src }});
  },
  props: {
   src: { type: String, required: true },
  },
 },
 },

通过createElement 创建一个元素<link></ link> ,引入css

export default {
 components: {
  'remote-css': {
  render(createElement) {
   return createElement('link', { attrs: { rel: 'stylesheet', href: this.href}});
  },
  props: {
   src: { href: String, required: true },
  },
 },
 },
}

望有用之,有问题望告知

全部评论