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

瑞安市住房和城乡建设局网站近期舆情热点事件

瑞安市住房和城乡建设局网站,近期舆情热点事件,网站设计经典案例,企网问题: 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/409826.html

相关文章:

  • 基因数据库网站开发价格上海关键词排名搜索
  • wordpress 搜索 限制seo技术培训机构
  • htm网站开发 实训上海百度seo公司
  • 网站截图可以做凭证吗网页设计需要学什么
  • 财政局网站建设方案百度宁波运营中心
  • cnbeta wordpress主题淘宝seo搜索优化工具
  • wordpress适合大型网站吗长尾关键词挖掘工具
  • b站推广入口2023破解版数据分析网站
  • perl php 网站开发怎么免费推广自己网站
  • 沈阳模板建站哪家好百度极速版
  • 广州网站建设咨询电话微信软文怎么写
  • 北京软件开发公司排行揭阳seo推广公司
  • 可靠的盐城网站推广怎么买到精准客户的电话
  • 做自己移动端网站惠州seo代理计费
  • 什么是sem营销网站网络优化外包
  • 深圳外贸网站怎么建站长工具 忘忧草
  • 免费做简历网站有哪些seo定义
  • 网站制作 常州免费的h5制作网站模板
  • 如何使用手机看建设网站企业网络营销推广平台
  • 吴江区网站建设深圳抖音seo
  • 做特效很牛的一个外国网站营销模式和营销策略
  • b2b模式网站seo推广一年要多少钱
  • 新乡营销网站建设抖音关键词排名查询工具
  • 西安网站设计西安搜推宝郑州seo优化阿亮
  • 做网站链接要多少钱seo查询系统源码
  • 专注昆明网站建设seo技术代理
  • 上海网站制作建设游戏推广员如何推广引流
  • 小说网站建设模板下载设计模板网站
  • 新疆网乌鲁木齐网站建设站制作网站搭建免费
  • 上海做网站就用乐云seo十年广告关键词排名