v-slot和slot、slot-scope之间相互替换实例
如果组件文档里面用的是v-slot,而你用的是vue2.6之前的版本,则需要替换v-slot所以有两种替换方式,注意看两块v-slot有啥不同,你就知道你该怎么用slot-scope和slot来替换文档中的v-slot了
v-slot使用方式1
<template v-slot:operate="{ row }"><template>
则可替换为
<template slot="operate" slot-scope="{ row }"></template>
v-slot使用方式2
<template v-slot="{ row }"><template>
则可替换为
<template slot-scope="row"></template>
先记录后期再完善,赶项目去了
补充知识V-for and slot-scoped报错问题
此场景是为了用v-for动态渲染表格的slot
可能会这么写
<a-table> <span v-for="(item, index) in header" :key="index" :slot="item.dataIndex" slot-scope="text" > {{ text }} </span> </a-table>
这样子会报错,因为v-for和slot-scope在同一级
Ambiguous bined usage of slot-scope and v-for on (v-for takes higher priority). Use a wrapper < template> for the scoped slot to make it clearer.
提示在外边包一层< template>,于是你可能改成狼蚁网站SEO优化这样,也会报错
<a-table> <template v-for="(item, index) in header" :key="index"> <span :slot="item.dataIndex" slot-scope="text" > {{ text }} </span> </template> </a-table> < template> cannot be keyed. Place the key on real elements instead.
提示< template>template不能写key, 即使没有这个错,表格数据也不会渲染出来,因为这一层没有slot,应该说slot应该是放最外面,把:key放里面
改成如下
<a-table> <template v-for="(item, index) in header" :slot="item.dataIndex" slot-scope="text"> <span :key="index"> {{ text }} </span> </template> </a-table>
以上解决问题
有个slot没有渲染的问题
<template v-for="(slotname, idx) in ['status', 'sub_aount_status']" :slot="slotname" slot-scope="text" > <span :key="idx"> <a-tag v-if="text === '正常'" color="blue">{{ text }}</a-tag> <a-tag v-else color="red">{{ text }}</a-tag> </span> </template> <!-- 包名称、关联账号 --> <template v-for="(slotname, idx) in ['app_name', 'roles']" :slot="slotname" slot-scope="text" > <span :key="idx"> <a-tooltip placement="" > <template slot="title"> <span v-for="(item, index) in text" :key="index">{{ item }}<br/></span> </template> <div class="tableHidden"> <a-tag v-for="(item, index) in text" :key="index">{{ item }} </a-tag> </div> </a-tooltip> </span> </template>
好像是因为2个v-for="(slotname, idx)"里的slotname名字一样了,对的,就是取的临时变量名,修改成不一样的就好了,神奇
<template v-for="(name, idx) in ['status', 'sub_aount_status']" :slot="name" slot-scope="text" > // 上面那个name <span :key="idx"> 。。。 </span> </template> <!-- 包名称、关联账号 --> <template v-for="(slotname, idx) in ['app_name', 'roles']" :slot="slotname" slot-scope="text" > <span :key="idx"> 。。。 </a-tooltip> </span> </template>
以上这篇v-slot和slot、slot-scope之间相互替换实例就是长沙网络推广分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持狼蚁SEO。
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指