新写一个组件 remote 组件,然后组件里 src 的值通过 props 传递。

<template>
  <remote src="https://public.tableau.com/javascripts/api/tableau-2.min.js"> </remote>
</template>

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

else:

How to include a <script> tag on a Vue component

created() {
  const el = document.createElement('script');
  el.setAttribute('src', 'https://res.wx.qq.com/open/js/jweixin-1.3.2.js');
  document.head.appendChild(el);
}

 

Logo

前往低代码交流专区

更多推荐