我在 2.7 版中使用帶有 Composition API 的 Vue,我正在努力解決一件事。我想根據反應值動態渲染一個組件。這是代碼:
const renderTab = ref('admin');
// and later in template
<component :is="renderTab"></component>
問題是我收到錯誤:
Unknown custom element: <admin>
我列印的價值 {{ renderTab }}和它的正確性。對我來說非常令人困惑的事實是,我可以毫無問題地像這樣呼叫這個組件:
<admin></admin>
或者像這樣:
<component :is="'admin'"></component>甚至像這樣:
<component is="admin"></component>
我錯過了什么或做錯了什么?
uj5u.com熱心網友回復:
組件在用作動態組件之前需要決議。對于全域注冊的組件,它可以是:
const Admin = resolveComponent('Admin')
const renderTab = ref(Admin);
對于本地組件,直接匯入和使用更簡單Admin。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/535588.html
標籤:vue.js
