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

个人工作室网站上海建设银行网站转账记录查询

个人工作室网站,上海建设银行网站转账记录查询,杭州seo哪家好,wordpress修改文章页面模板动态组件的基本使用 动态组件(Dynamic Components)是一种在 Vue 中根据条件或用户输入来动态渲染不同组件的技术。 在 Vue 中使用动态组件,可以使用 元素,并通过 is 特性绑定一个组件的名称或组件对象。通过在父组件中改变 is 特…

动态组件的基本使用

动态组件(Dynamic Components)是一种在 Vue 中根据条件或用户输入来动态渲染不同组件的技术。

在 Vue 中使用动态组件,可以使用 元素,并通过 is 特性绑定一个组件的名称或组件对象。通过在父组件中改变 is 特性的值,可以动态切换渲染的组件。

第一种写法

A.vue

<template><div>A component</div>
</template><script setup lang="ts"></script><style scoped></style>

B.vueC.vue 同理

APP.vue

<template><div style="display: flex;"><!-- class可以写两个,一个静态,一个动态 --><div @click="switchCom(item, index)" :class="[active == index ? 'active' : '']" class="tabs"v-for="(item, index) in data"><div>{{ item.name }}</div></div></div><component :is="comId"></component>
</template><script setup lang="ts">
import { ref, reactive } from 'vue';
import AVue from './components/A.vue'
import BVue from './components/B.vue'
import CVue from './components/C.vue'
// 这里不需要将对象中所有数据变为响应式,可以使用ref
const comId = ref(AVue)
const active = ref(0)const switchCom = (item, index) => {comId.value = item.comactive.value = index
}const data = reactive([{name: 'A',com: AVue},{name: 'B',com: BVue},{name: 'C',com: CVue}
])
</script><style lang="scss" scoped>
.active {background: blueviolet;
}.tabs {border: 1px solid #ccc;padding: 5px 10px;margin: 5px;cursor: pointer;}
</style>

在这里插入图片描述

第二种写法

APP.vue

<template><div style="display: flex;"><!-- class可以写两个,一个静态,一个动态 --><div @click="switchCom(item, index)" :class="[active == index ? 'active' : '']" class="tabs"v-for="(item, index) in data"><div>{{ item.name }}</div></div></div><component :is="comId"></component>
</template><script setup lang="ts">
// markRaw:作用:标记一个对象,使其永远不会再成为响应式对象。
import { ref, reactive, markRaw, shallowRef } from 'vue';// 这里不需要将对象中所有数据变为响应式,可以使用ref
const comId = shallowRef('AVue')
const active = ref(0)const switchCom = (item, index) => {comId.value = item.comconsole.log(comId.value);active.value = index
}const data = reactive([{name: 'A',com:'AVue'},{name: 'B',com:'BVue'},{name: 'C',com:'CVue'}
])
</script><script lang="ts">
import AVue from './components/A.vue'
import BVue from './components/B.vue'
import CVue from './components/C.vue'export default {components: {AVue,BVue,CVue}
}
</script><style lang="scss" scoped>
.active {background: blueviolet;
}.tabs {border: 1px solid #ccc;padding: 5px 10px;margin: 5px;cursor: pointer;}
</style>

性能优化

上述第一种写法代码会出现警告
在这里插入图片描述
输出 comId 的值,出现 comId 的属性被劫持,出现性能浪费
在这里插入图片描述

解决方法

使用markRawshallowRef这两个API

App.vue

<template><div style="display: flex;"><!-- class可以写两个,一个静态,一个动态 --><div @click="switchCom(item, index)" :class="[active == index ? 'active' : '']" class="tabs"v-for="(item, index) in data"><div>{{ item.name }}</div></div></div><component :is="comId"></component>
</template><script setup lang="ts">
// markRaw:作用:标记一个对象,使其永远不会再成为响应式对象。
import { ref, reactive, markRaw, shallowRef } from 'vue';
import AVue from './components/A.vue'
import BVue from './components/B.vue'
import CVue from './components/C.vue'
// 这里不需要将对象中所有数据变为响应式,可以使用ref
const comId = shallowRef(AVue)
const active = ref(0)const switchCom = (item, index) => {comId.value = item.comconsole.log(comId.value);active.value = index
}const data = reactive([{name: 'A',com: markRaw(AVue)},{name: 'B',com: markRaw(BVue)},{name: 'C',com: markRaw(CVue)}
])
</script><style lang="scss" scoped>
.active {background: blueviolet;
}.tabs {border: 1px solid #ccc;padding: 5px 10px;margin: 5px;cursor: pointer;}
</style>

再次输出 comId 的值,解决性能浪费的问题
在这里插入图片描述

http://www.yayakq.cn/news/668919/

相关文章:

  • 怎么让公司网站显示官网万网怎么建设网站
  • 深圳自适应网站建设吕子乔做网站吹的语录
  • wordpress自动上传外链图片大连知名的seo外包
  • 防水网站建设国外服务器地址ip
  • 手机网站被自动跳转网站编辑没有经验可以做吗
  • 钟村免费建站公司网站首页调用网站标题
  • 印刷网站模板下载千页网素材官网入口
  • 手机网站刷排名wordpress user_activation_key
  • 最新网站建设视频wordpress主题透明
  • 免费建站的方法潍坊网站制作报价
  • 网站获取qq号码 代码游戏网页设计模板图片
  • 贸易公司网站建设价格推广注册app拿佣金平台
  • 广东省路桥建设发展有限公司网站网络维护与故障解决
  • 网站建设服务器要求上海门户网站制
  • 广州网站开发 英诺科技门户网站指的是什么
  • 查询成绩的网站怎么做一个网站如何做推广方案设计
  • 网站的建设费 账务处理网站后台无法上传图片
  • 专业商城网站制作免费广告投放平台
  • 网站ui升级怎么做网站备案帐号是什么情况
  • 怎么知道一个网站是哪家公司做的阿里万网怎么做网站
  • 网盟官方网站wordpress近期文章图片
  • 大有网网站顺德外贸网站建设
  • 网站 多少篇文章才能上线wordpress托管服务
  • 电商网站建设开发公司做外贸如何分析客户网站
  • 网站后台怎么用ftp打开哪里可以做网站开发
  • 建网站 端口电子商务网站名字
  • 基于互联网怎样做网站推广潍坊网站seo
  • 建设项目环保验收公示网站如何建设一个新的网站
  • 南京列表网免费发布信息长沙seo网站管理
  • 网站搭建系统都有哪些查询网站备案时间查询