当前位置: 首页 > wzjs >正文

网站建设的过程西安楼市最新房价

网站建设的过程,西安楼市最新房价,wordpress wp_handle_upload,北京室内设计问题: vue3循环渲染动态组件component不生效,页面空白 在vue3使用component动态组件展示组件时,组件就是不展示显示空白。在vue2中使用动态变量component展示组件都是没问题。试了很多方法 踩了很多坑,所以记录下: &l…

问题: vue3循环渲染动态组件component不生效,页面空白

在vue3使用component动态组件展示组件时,组件就是不展示显示空白。在vue2中使用动态变量component展示组件都是没问题。试了很多方法 踩了很多坑,所以记录下:

  <div class="preview-list" id="canvas-area"><componentv-for="component in components" :key="component.id":is="component.name"v-bind="component.props" /></div>
<script setup lang="ts">
import LText from '@/components/LText'
import { ref } from 'vue'
interface styleProps = {text: string;fontSize: string;
}
interface componentData = {id: number;name: string;props?: styleProps;
}
const components = ref<componentData[]>([{ id: 1, name: 'LText', props: { text: 'hello', fontSize: '12px'}},{ id: 2, name: 'LText', props: { text: 'hello2', fontSize: '14px'}},{ id: 3, name: 'LText', props: { text: 'hello3', fontSize: '16px'}}
])
</script>

因为vue3使用的是setup语法,组件只要import导入就行 不需要再像vue2中在components挂载,这样导致我想渲染的组件是没有渲染出来页面出现空白,尝试了很多办法对应的组件里面添加多个script指定对应的组件名,还是没生效

解决方法

使用shallowReactive或者shallowRef把对应的组件名称重新定义下,遍历component时,is采用对象key获取对应的对应的组件,这样组件就显示出来了

  <div class="preview-list" id="canvas-area"><componentv-for="component in components" :key="component.id":is="componentsName[component.name]"v-bind="component.props" /></div>
<script setup lang="ts">
import LText from '@/components/LText'
import { ref, shallowReactive } from 'vue'
interface styleProps = {text: string;fontSize: string;
}
interface componentData = {id: number;name: string;props?: styleProps;
}
type componentName = {[key: string]: any
}
const components = ref<componentData[]>([{ id: 1, name: 'LText', props: { text: 'hello', fontSize: '12px'}},{ id: 2, name: 'LText', props: { text: 'hello2', fontSize: '14px'}},{ id: 3, name: 'LText', props: { text: 'hello3', fontSize: '16px'}}
])
// 解决方案
const componentsName = shallowReactive<componentName>({LText
})</script>
http://www.dtcms.com/wzjs/391896.html

相关文章:

  • 基层政府网站建设常州seo招聘
  • 安阳县疫情最新消息南宁seo外包服务
  • 做鸭子的网站怎样把自己的产品放到网上销售
  • 手机网站建设服务器无锡整站百度快照优化
  • 建设集团网站 技术支持中企动力济南seo外包服务
  • 北京北站如何在百度做推广
  • markdown做网站编辑器百度手机助手苹果版
  • 水利部建设项目水资源论证网站西安互联网推广公司
  • 微网站首选公司seo推广岗位职责
  • 建设银行网上银行网站打不开百度推广费用一年多少钱
  • 做国外商品的网站网站制作详细流程
  • 网站排名优化多少钱智慧软文发稿平台官网
  • 做综合医院网站如何做网络推广人员
  • 网站banner 大小如何创建网站?
  • 黑色网站模板关键词你们都搜什么
  • 怎么做像表白墙的网站营销推广是什么意思
  • 做图片网站 解决版权怎样自己做网站
  • 技术支持 佛山网站建设网络推广的含义
  • 荣耀手机好口碑的关键词优化
  • 用java怎么做游戏下载网站吗沙坪坝区优化关键词软件
  • 多页网站模板图片识别
  • 奶茶网站建设域名收录查询
  • 用照片做模板下载网站好成功的软文营销案例
  • 百度收录不到公司网站广告买卖网
  • 企业网站建设视频营销技巧有哪些
  • wordpress runcodeseo网络推广公司排名
  • 开发一个b2c购物网站抖音推广平台
  • 帝国做的网站打开速度外链
  • 做片头的网站网上销售有哪些方法
  • 公司如何做自己的网站优化排名