最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

vue.js - How to use Vuetify in Vue SFC Playground? - Stack Overflow

programmeradmin1浏览0评论

I am trying to use both Vue Router and Vuetify in Vue SFC Playground. I began with the Vue Playground example of Vue Router (taken from Getting Started). This had Vue Router already imported, so I only needed to import Vuetify. Firstly, I imported Vuetify in Import Map:

{
  "imports": {
    /* ... */
    "vuetify": "/[email protected]/dist/vuetify.esm.js"
  },
  "scopes": {}
}

Then, I imported Vuetify in main.js:

import { createApp } from 'vue'
import { createVuetify } from 'vuetify'
import router from './router'
import App from './app.vue'

const vuetify = createVuetify()

createApp(App)
  .use(vuetify)
  .use(router)
  .mount('#app')

Finally, I placed a Vuetify component in app.vue:

<template>
  <v-app>
    <v-main>
      <v-app-bar>
        <h1>Hello App!</h1>
      </v-app-bar>
    </v-main>
  </v-app>
  <!-- ... -->
</template>

However, I noticed that CSS is missing since it wasn't imported. In Vuetify Playground, there is a section named "Links" for importing CSS:

{
  "css": ["/[email protected]/dist/vuetify-labs.css"]
}

But I didn't find it in Vue Playground. So, what is the correct way to import CSS?


I also tried Vuetify Playground at the very beginning, which had Vuetify already imported, so I only needed to import Vue Router. However, it seems that there is no way to call .use(router) because the createApp(App) part is not editable. If someone finds out a way to import Vue Router in Vuetify Playground, that also counts as a solution.

I am trying to use both Vue Router and Vuetify in Vue SFC Playground. I began with the Vue Playground example of Vue Router (taken from Getting Started). This had Vue Router already imported, so I only needed to import Vuetify. Firstly, I imported Vuetify in Import Map:

{
  "imports": {
    /* ... */
    "vuetify": "https://unpkg/[email protected]/dist/vuetify.esm.js"
  },
  "scopes": {}
}

Then, I imported Vuetify in main.js:

import { createApp } from 'vue'
import { createVuetify } from 'vuetify'
import router from './router'
import App from './app.vue'

const vuetify = createVuetify()

createApp(App)
  .use(vuetify)
  .use(router)
  .mount('#app')

Finally, I placed a Vuetify component in app.vue:

<template>
  <v-app>
    <v-main>
      <v-app-bar>
        <h1>Hello App!</h1>
      </v-app-bar>
    </v-main>
  </v-app>
  <!-- ... -->
</template>

However, I noticed that CSS is missing since it wasn't imported. In Vuetify Playground, there is a section named "Links" for importing CSS:

{
  "css": ["https://cdn.jsdelivr/npm/[email protected]/dist/vuetify-labs.css"]
}

But I didn't find it in Vue Playground. So, what is the correct way to import CSS?


I also tried Vuetify Playground at the very beginning, which had Vuetify already imported, so I only needed to import Vue Router. However, it seems that there is no way to call .use(router) because the createApp(App) part is not editable. If someone finds out a way to import Vue Router in Vuetify Playground, that also counts as a solution.

Share Improve this question asked Mar 11 at 11:56 TripleCameraTripleCamera 936 bronze badges 1
  • Those are playgrounds, I'd say that for something a tidy bit more complex it's just faster to provide a hosted github link at some point. Otherwise give a try to a codesandbox/stackblitz with the full app running there. – kissu Commented Mar 11 at 13:33
Add a comment  | 

1 Answer 1

Reset to default 2

Vuetify playground is a fork of Vue playground, so their functionality doesn't match.

Since the playground doesn't use fully functional bundler like Vite, it may be impossible to load CSS files the same way this would be done in regular Vue project, import 'vuetify/styles'.

E.g. this works in SFC but can cause problems with hot reload (demo):

<style>
@import 'https://unpkg/[email protected]/dist/vuetify.min.css'
</style>

Not relying on playground internals will cause less problems (demo):

...
import { createVuetify } from 'vuetify'

const link = document.createElement('link');
link.href = 'https://unpkg/[email protected]/dist/vuetify.min.css';
link.rel = 'stylesheet';
document.head.appendChild(link);

createApp(App)
  .use(router)
  .use(createVuetify())
  .mount('#app')

vuetify needs to be specified in import maps:

"vuetify": "https://unpkg/[email protected]/dist/vuetify.esm.js"
发布评论

评论列表(0)

  1. 暂无评论