Как программно импортировать / вводить файл s css с помощью Nuxt? - PullRequest
0 голосов
/ 06 мая 2020

Что касается вопроса, мне нравится загружать разные темы по переменной имени, но я всегда получал пустой объект из themeLoader.

Я нашел много бумаги, но не получил ответа. надеюсь, что кто-то может мне помочь.

function themeLoader (name) {
  return import(`../assets/themes/${name}.scss`)
}
export default {
  ...
  async fetch () {
    const name = 'test'
    console.log(themeLoader(name))
    const style = document.createElement('style')
    style.content = cssString
    // append to head
  }
  ...
}

Обновление

Я перемещаю импорт в функцию nuxt head, но я хочу знать, правильно ли я поступаю?

head () {
    const name = 'test'
    // eslint-disable-next-line
    import(/* webpackChunkName: "themes/[request]" */'../assets/themes/' + name + '/index.scss')
    return {
      title: this.docTitle
    }
  }
...