unplugin / unplugin-vue-components

📲 On-demand components auto importing for Vue
https://www.npmjs.com/package/unplugin-vue-components
MIT License
3.77k stars 349 forks source link

feature proposal: make <component :is='xx' work #643

Closed lishaobos closed 1 year ago

lishaobos commented 1 year ago

Clear and concise description of the problem

<component :is='xx' is not work.

Suggested solution

user can provide some comments:

/* unplugin-vue-components ['name1', 'name2'] */

or we can provide API like this:

defineUnpluginComponents(
    ['name1', 'name2']
)

and then we auto imported name1,name2

before

(_openBlock(), _createBlock(_resolveDynamicComponent("name1")))

after

import name1 from 'xx'
import name2 from 'xx'

const _getUnpluginDynamicComponent = name => {
  const _unpluginDynamicComponent = {
      name1,
      name2
  }

  return _unpluginDynamicComponent[name] || name
}

// we can replace the _resolveDynamicComponent
(_openBlock(), _createBlock(_resolveDynamicComponent(_getUnpluginDynamicComponent("name1"))))

// or we can inject components
defineCompoennt({
  components: { name1, name2  },
  setup() {
  // ...
  }
})

Alternative

No response

Additional context

No response

Validations

lishaobos commented 1 year ago

@antfu need some advice.

antfu commented 1 year ago

Thanks, but no. This is considered out of scope. If you need to do that, I'd suggest importing components explicitly or registering them as global components.

lishaobos commented 1 year ago

ok, i got it