在浏览器中渲染vue SFC组件

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Untitled</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css" />
<script>
  window.process ??= {};
  process.env = {};
  process.env.NODE_ENV = "development";
</script>

<!--
  JSPM Generator Import Map
  Edit URL: https://generator.jspm.io/#U2VhYGBmD80rySzJSU1hSM1JzU3NK9EtyCktdjDSM9YzYygrTTXWLU5L1s3JT0xJLXIw0LPQMwGJOhgD5U0AL/MVwEEA
-->
<script type="importmap">
  {
    "imports": {
      "element-plus": "https://ga.jspm.io/npm:element-plus@2.3.6/es/index.mjs",
      "vue": "https://ga.jspm.io/npm:vue@3.3.4/dist/vue.esm-browser.js",
      "vue3-sfc-loader": "https://ga.jspm.io/npm:vue3-sfc-loader@0.8.4/dist/vue3-sfc-loader.js"
    },
    "scopes": {
      "https://ga.jspm.io/": {
        "@ctrl/tinycolor": "https://ga.jspm.io/npm:@ctrl/tinycolor@3.6.0/dist/module/public_api.js",
        "@element-plus/icons-vue": "https://ga.jspm.io/npm:@element-plus/icons-vue@2.1.0/dist/index.js",
        "@floating-ui/core": "https://ga.jspm.io/npm:@floating-ui/core@1.3.0/dist/floating-ui.core.browser.mjs",
        "@floating-ui/dom": "https://ga.jspm.io/npm:@floating-ui/dom@1.2.9/dist/floating-ui.dom.browser.mjs",
        "@popperjs/core": "https://ga.jspm.io/npm:@sxzz/popperjs-es@2.11.7/dist/index.mjs",
        "@vue/reactivity": "https://ga.jspm.io/npm:@vue/reactivity@3.3.4/dist/reactivity.esm-browser.js",
        "@vue/runtime-dom": "https://ga.jspm.io/npm:@vue/runtime-dom@3.3.4/dist/runtime-dom.esm-browser.js",
        "@vue/shared": "https://ga.jspm.io/npm:@vue/shared@3.3.4/dev.index.js",
        "@vueuse/core": "https://ga.jspm.io/npm:@vueuse/core@9.13.0/index.mjs",
        "@vueuse/shared": "https://ga.jspm.io/npm:@vueuse/shared@9.13.0/index.mjs",
        "async-validator": "https://ga.jspm.io/npm:async-validator@4.2.5/dist-web/index.js",
        "dayjs": "https://ga.jspm.io/npm:dayjs@1.11.8/dayjs.min.js",
        "dayjs/plugin/": "https://ga.jspm.io/npm:dayjs@1.11.8/plugin/",
        "escape-html": "https://ga.jspm.io/npm:escape-html@1.0.3/index.js",
        "lodash-es": "https://ga.jspm.io/npm:lodash-es@4.17.21/lodash.js",
        "lodash-unified": "https://ga.jspm.io/npm:lodash-unified@1.0.3/import.js",
        "memoize-one": "https://ga.jspm.io/npm:memoize-one@6.0.0/dist/memoize-one.esm.js",
        "normalize-wheel-es": "https://ga.jspm.io/npm:normalize-wheel-es@1.2.0/dist/index.mjs",
        "vue-demi": "https://ga.jspm.io/npm:vue-demi@0.14.5/lib/index.mjs"
      }
    }
  }


</script>

<div id="app"></div>
<!-- ES Module Shims: Import maps polyfill for olrder browsers without import maps support (eg Safari 16.3) -->
<script async src="https://ga.jspm.io/npm:es-module-shims@1.7.3/dist/es-module-shims.js"
        crossorigin="anonymous"></script>

<script type="module">
  import * as Vue from "vue";
  import ElementPlus from "element-plus";
  import Vue3SfcLoader from "vue3-sfc-loader";


  const template = `
  <script>
    import {ElButton, ElEmpty} from "element-plus";
    export default {
      components: {
        ElButton,
        ElEmpty
      }
    }
  \<\/script>
  <template>
    <el-button>hello</el-button>
    <el-empty></el-empty>
</template>
  `;

  const options = {
    moduleCache: {
      vue: Vue,
      "element-plus": ElementPlus
    },
    async getFile(url) {
      return {
        getContentData: () => Promise.resolve(template)
      };
    },
    addStyle(textContent) {

      const style = Object.assign(document.createElement("style"), { textContent });
      const ref = document.head.getElementsByTagName("style")[0] || null;
      document.head.insertBefore(style, ref);
    }
  };

  const app = Vue.createApp({
    components: {
      "App": Vue.defineAsyncComponent(() => {
        return Vue3SfcLoader.loadModule("App.vue", options);
      })
    },
    template: "<App/>"
  });

  app.use(ElementPlus);
  app.mount("#app");
</script>
</body>
</html>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值