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

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

如何為 Vue 組件實現策略模式

如何為 Vue 組件實現策略模式

滄海一幻覺 2023-11-12 15:38:50
所以事情是這樣的。我有一個Cat,Dog和 ,Horse它們都實現了該Animal接口。對于每一個,我都有一個DogComponent,CatComponent和HorseComponent。問題:如何創建一個在不使用或一堆s 的情況下AnimalComponent接受任何Animal但渲染的組件?DogComponentDogswitch-casev-if<template>請假設僅渲染不同的imageUrl和title是不夠的。
查看完整描述

1 回答

?
不負相思意

TA貢獻1777條經驗 獲得超10個贊

只需使用Vue 動態組件:)

這個特殊組件根據屬性中提供的名稱呈現一個組件is

<template>

? <component v-for="animal in animals" :is="`${animal.type}-component`"/>

</template>


<script>

// vue syntax omitted for simplicity

animals: [

? { type: 'dog' },

? { type: 'cat' },

]

</script>


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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