亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JS 和 Vue.js 中的動態導入

JS 和 Vue.js 中的動態導入

湖上湖 2023-09-28 16:44:04
我正在使用 Vue.js 框架編寫一個 Web 應用程序。需要使用動態導入。您需要使用參數及其名稱進行導入,然后定義生成的組件。  js中動態導入的語法如下:  async () => {      const module_path = 'module_path';      const module = await import(module_path)      module.default();    }  因此,只能在異步函數內使用動態導入的庫。我需要在其他地方使用導入的組件:  <template>     <div>        <!-- imported component definition -->        <component v-bind:is="my_component"></component>     </div>  </template>  <script>     # Here you need to dynamically import the component, so that you      # can define it later on line 3.     # How to make a static import is clear (shown below). But I need a      # dynamic one.     import my_component from "./component_title.Vue"          export default {        props: () -> {           # The name of the component to be imported.           # Transferred from another component.           component_title: {type: String, default: null}        }        components: {           # The component is declared           my_component: my_component        }     }  </script>  這個任務可以實現動態導入嗎?
查看完整描述

1 回答

?
aluckdog

TA貢獻1847條經驗 獲得超7個贊

是的。import()只需在您的組件中使用:

components: { 
  my_component: () => import(path)
}


查看完整回答
反對 回復 2023-09-28
  • 1 回答
  • 0 關注
  • 100 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號