FranckFreiburger / vue3-sfc-loader

Single File Component loader for Vue2 and Vue3. Load .vue files directly from your HTML. No node.js environment, no build step.
MIT License
1.03k stars 116 forks source link

I encountered a bug when using import default #140

Closed huangbaihei closed 5 months ago

huangbaihei commented 1 year ago

When I use import dayjs from "dayjs", the dayjs I get is not the default export, but the whole module. Dayjs has been put into modulecache

FranckFreiburger commented 5 months ago

include the dayjs library in the global scope

<script src="https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js"></script>

add dayjs library to the moduleCache

const options = {
  moduleCache: {
    vue: Vue,
    dayjs
  },
  ...

use the dayjs in your component

<script>
  import dayjs from 'dayjs'
  alert(dayjs().format())
</script>
FranckFreiburger commented 5 months ago

request to be reopened as needed