[Vuejs]-How to import a nuxt component if exist otherwise import a default component

-1👍

This should work.

export default {
  methods: {
    comptest() {
      let xxx
      try {
        xxx = require('~/components/${process.env.THEME}/test1.vue')
      } catch(e) {
        xxx = require('~/components/test.vue')
      }
      return xxx
    }
  }
}

Leave a comment